#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    34
    Rep Power
    11

    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?

    Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    34
    Rep Power
    11
    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?
  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    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:

    Code:
    root = Tk()
    
    def periodic():
        print "Doing some processing"
        root.after(200,periodic)
    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.


    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().
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    34
    Rep Power
    11
    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
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    34
    Rep Power
    11
    (bump)

    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.
  10. #6
  11. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    It is difficult to diagnose the problem without some code to look at but It sounds like you are not using the mainloop() method.

    grim

IMN logo majestic logo threadwatch logo seochat tools logo