Python Forum

Full Version: Tkinter GUI freeze
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm using python 3.6.7 on Windows

I'm making a Tkinter GUI that will let you upload files to a destination using ftplib.
My problem is that if the files are big, the GUI will freeze (not responding) because the mainloop can't process the event, until the file are uploaded and the GUI are responsive again

I'm will not perform other actions while uploading files, but i would like to avoid that the GUI freeze completely.

Here is the function i'm calling
def loadDropdownFiles(self, txutmp):
    ftp = FTP(ipdest)
    ftp.login(user='xxx', passwd='xxx')
    ftp.cwd(txutmp)
    localfile = open(promodest, 'rb')
    ftp.storbinary('STOR ' + "promo.zip", localfile)
    tp.quit()
Any tips on how i can avaid the GUI freeze?
Call the function using after(), which will run the function in a separate process
some_widget.after(100, loadDropdownFiles, txutmp))  ## call after 1/10 of a second 
(Jun-21-2019, 01:06 AM)woooee Wrote: [ -> ]Call the function using after(), which will run the function in a separate process
some_widget.after(100, loadDropdownFiles, txutmp))  ## call after 1/10 of a second 

Just calling the method using after will not run the function in a separate process, after makes thing happen in the GUI's thread after a period of time, its the waiting time period itself that is in a different thread, the above will just delay the freezing.
Refer to the linked thread in my previous post, where a separate thread is used on the blocking code and after is used to make thread safe calls back to the GUI.
Thank you Yoriz. exactly what i neded