July 29th, 2004, 06:37 PM
Two Miscellaneous TKinter Questions
- How do I get rid of that god forsaken console window?
- How does one set the title of one's TKinter window?
July 29th, 2004, 08:13 PM
Make that three:
I have a tk app, and besides the 'mainloop', it has another thread doing the core objective of the application. In the __init__ definition of the App class for tkinter, i define and pack my widgets. Then, and this is the gray area, I execute my core thread, which is an endless loop, and then my App class enters its own endless loop. So what I'm asking, is, is this the right way to do this? Because unless i comment out the starting of the thread and the endless loop in init, the window never appears. can someone help me out?
July 30th, 2004, 03:29 AM
1. I assume you are running in Windows - in which case change the file extension from .py to .pyw
2. root.title("Some Text") where root is the window object.
Tkinter (And most other GUI frameworks) are designed for programs that rely on events. If your program basically "busy waits" processing code then Tkinter will never run properly.
You should try to arrange for some pauses in the data processing portion of your code e.g. time.sleep(x) and break it up into chunks.
A very good tool to use is the "after" method:
For example I have a Tkinter app that interfaces with serial ports and needs to check for incoming data and process it.
Every 200 ms or so my periodic function is called that reads the port and processes the data - something like:
This then gives the GUI plenty of idle time to update things if you arrange the periodic function to only run for say less than 100 ms. This means the GUI will be updated maybe three times a second.
root = Tk()
print "Doing some processing"
One (dirty?) trick I've used before is to pass a busy thread a link to the root and periodically force an update by changing something in the GUI or just calling root.update().
July 30th, 2004, 07:30 PM
Thank you very much for your response. So, just for clarity: you're suggesting I scatter brief pauses throughout my core coding?
Edit: I did this in my core thread and the __init__ of App, but to no avail
July 31st, 2004, 05:26 PM
I also tried your "dirty" way, putting root.update()'s in the core thread (after passing it down and putting it into self) and in the while loop inside of the __init__ of my Tk class, however it didn't work. Then I realized that the window probably wasn't showing up until that __init__() finished, so i made the while loop its own function, put another button on my window, and made it so when you clicked the button it called the function containing the endless loop (even now, it has the root.update()'s in it), and when you click that button, the application just freezes, so to speak.
August 9th, 2004, 02:52 AM
It is difficult to diagnose the problem without some code to look at but It sounds like you are not using the mainloop() method.