mathewthe2 / Game2Text

Complete toolbox for gamifying language learning
https://www.Game2Text.com
Apache License 2.0
194 stars 26 forks source link

askopenfile not working on Mac. Switch to javascript open file window. #24

Open mathewthe2 opened 3 years ago

mathewthe2 commented 3 years ago

tkinter and askopen file won't work on Mac because it is running on a different thread.

It is also blocked on Windows sometimes by other tasks.

Remove tkinter and use javascript .

Example

function openFileDialog (accept, callback) {  // this function must be called from  a user
                                              // activation event (ie an onclick event)

    // Create an input element
    var inputElement = document.createElement("input");

    // Set its type to file
    inputElement.type = "file";

    // Set accept to the file types you want the user to select. 
    // Include both the file extension and the mime type
    inputElement.accept = accept;

    // set onchange event to call callback when user has selected file
    inputElement.addEventListener("change", callback)

    // dispatch a click event to open the file dialog
    inputElement.dispatchEvent(new MouseEvent("click")); 
}