In looking at your code, there are a few things I would do:
- Subclass TK..
class MainGUI(Tk): - Attach all gui components to this class.... your frame for example.
- Add a queue and a polling method for GUI updates to the MainGUI class (this may help fix your freezing issue). You can use the TK.after method to ask the mainloop to do this periodically.
- Do the heavy lifting items such as db reads, filesystem, etc in a separate thread if they block too long, but make sure they don't update the GUI directly from that thread, you can pass a reference to the GUI to them and they should place a callback on the updateq for the main loop to execute as it runs a polling cycle.
- Check the code for pep8 compliance.
Here is an example of how I have done GUI's using TKinter:
class MainGUI(Tk):
""" The GUI """
def __init__(self):
super().__init__()
self.updateq = queue.Queue()
# Build main components
# Layout components
# Key bindings
self.poll()
self.mainloop()
def poll(self):
""" Polls the Queue for the arrival of various callbacks """
# You may want to process more or less callbacks each cycle...
# here it uses 100 as a maximum
for i in range(100):
if( self.updateq.empty()):
break
(callback, args) = self.updateq.get()
if( args):
callback(args)
else:
callback()
# Recursive call
self.after(50, self.poll)