Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 29th, 2004, 06:37 PM
dbickett dbickett is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 34 dbickett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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.

Reply With Quote
  #2  
Old July 29th, 2004, 08:13 PM
dbickett dbickett is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 34 dbickett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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?

Reply With Quote
  #3  
Old July 30th, 2004, 03:29 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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().
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #4  
Old July 30th, 2004, 07:30 PM
dbickett dbickett is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 34 dbickett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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

Reply With Quote
  #5  
Old July 31st, 2004, 05:26 PM
dbickett dbickett is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 34 dbickett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
(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.

Reply With Quote
  #6  
Old August 9th, 2004, 02:52 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Two Miscellaneous TKinter Questions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway