The following builds a two button window. "Run" will not "Quit". I have a structure problem. Can anyone please suggest a workaround. - #!/usr/bin/env python
-
from Tkinter import *
-
-
def start():
-
while True:
-
print "Stop me if you can from Quit"
-
root.update_idletasks()
-
-
root = Tk()
-
root.title('Example')
-
-
button1 = Button(root,text = 'Start', command = start)
-
button1.grid(row = 0, column = 0)
-
-
button2 = Button(root,text = 'Quit', command = root.destroy)
-
button2.grid(row = 1, column = 0)
-
-
root.mainloop()
10 1652 bvdet 2,851
Recognized Expert Moderator Specialist - def start():
-
print "Stop me if you can from Quit"
-
root.after(100, start)
bvdet 2,851
Recognized Expert Moderator Specialist
So, if you don't mean clicking the 'Quit' button after clicking the 'Start' button, what do you mean?
What you suggested did not work.
I have found that by changing "root.update_idletasks()" to
root.update() works. I have some tk learning to do. Thanks.
dwblas 626
Recognized Expert Contributor
It works for me using "after". Did you leave in the "while True" statement so it still hangs? In any case you have to be more specific than "What you suggested did not work" for more suggestions.
The following works. I need to figure out the difference between root.update() and root.update_idletasks(). -
-
#!/usr/bin/env python
-
from Tkinter import *
-
-
def start():
-
while True:
-
print "Stop me if you can from Quit"
-
root.update()
-
-
root = Tk()
-
root.title('Example')
-
-
button1 = Button(root,text = 'Start', command = start)
-
button1.grid(row = 0, column = 0)
-
-
button2 = Button(root,text = 'Quit', command = root.destroy)
-
button2.grid(row = 1, column = 0)
-
-
root.mainloop()
-
-
bvdet 2,851
Recognized Expert Moderator Specialist
It works fine if you remove the while loop. Did you try that?
The point was stop the while loop using "Quit" (button2).
Anyone know a good online tkinter resource?
bvdet 2,851
Recognized Expert Moderator Specialist
While not complete (for example it doesn't cover pack or place geometry), this is my go to for reference.
Regarding widget.update():
"This method forces the updating of the display. It should be used only if you know what you're doing, since it can lead to unpredictable behavior or looping. It should never be called from an event callback or a function that is called from an event callback.
In your solution, it exits the while loop, but does so by creating an exception. You will need to catch the exception or find a better way.
Oh wow, thanks for that reference! From my alma matter (1990).
I noticed the exception when run from terminal. Your right, I need work that. I will give that reference a good read before proceeding further.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Rob |
last post by:
My first GUI so be gentle...
When I start my program I call a class that runs the initial window. While
in this class if a certain button is pressed it calls a function outside the
class. This...
|
by: Charlie Lesh |
last post by:
Hey all:
Is there any way to draw on the 'root' window? I'm thinking about a
python screensaver for linux. I know that there are xlib bindings for
python, maybe a little outdated, but do they...
|
by: Mickel Grönroos |
last post by:
Hi everybody,
I'm using QuickTimeTcl (3.1) to be able to play movie files in my Tkinter
application (Python 2.3.2) on Windows 2000. I was planning to write a
simple wrapper class,...
|
by: Tim Jarman |
last post by:
Apologies in advance for the long post - I wanted to be sure I included all
the relevant details. The answer is probably very, very simple.
I am doing something stupid here, but I don't know what...
|
by: snoylr |
last post by:
This is my first day working with Tkinter. I'm using python2.3 on
WindowsXP. I found this program and entered it.
from Tkinter import *
class App:
def _init_(self,master):
frame =...
| |
by: mzdude |
last post by:
I've just started playing with Python. Installed 2.5 on Windows XP
system. I'm working through some of the examples in Programming Python
3ed by Mark Lutz. Given the following example when the Quit...
|
by: rhitam30111985 |
last post by:
hi all.. python noob here.. i am creating a GUI for an applcation... now i was just testing the working of askstring :
from tkSimpleDialog import askstring
string=askstring('site','enter site:')...
|
by: Sean DiZazzo |
last post by:
Is there any way to open a Tkinter.askopenfilename() without opening a
root window alongside the file chooser?
I simply want a script to open a dialog and return the chosen file's
path to...
|
by: MartinRinehart |
last post by:
Everything I've read about Tkinter says you create your window and
then call its mainloop() method. But that's not really true. This is
enough to launch a default window from the console:
...
|
by: Lie Ryan |
last post by:
On Wed, 01 Oct 2008 11:33:59 +0100, dudeja.rajat wrote:
The root window is the main window, not the DOS box. I think in windows,
you should use pythonw.exe or something to open the python...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |