Tkinter Window refresh
Niels Diepeveen
niels at endea.demon.nl
Fri Aug 25 13:03:57 EDT 2000
"Daley, Mark W" schreef:
>
> I am reposting this with the hopes that the answer lies with someone out
> there. I searched all the documentation and books I have, to no avail.
The answer is probably simple, but what exactly is the question?
>
> > I have no idea how to do this. I want to allow a user to manipulate a GUI
> (e.g., shrink it to the toolbar) while it is performing an operation in
> another thread.
If the real work is going on in a different thread, there should be no
problem, other than the usual problems with multithreading. Is this
anything like you want?
#-------------------------------------------------------------------
# DON'T run this in IDLE or PythonWin
# Obviously this should be wrapped up in some classes for a real
# program
from Tkinter import *
import threading
import time
stopped = 0
def bgt():
# What you do here doesn't really matter
# Just a demonstration
while not stopped:
ltext.set(str(int(ltext.get()) + 1))
time.sleep(0.5)
root.destroy()
def stop():
global stopped
stopped = 1
root = Tk()
ltext = StringVar(root)
ltext.set('0')
label = Label(root, textvariable=ltext)
label.pack()
button = Button(root, text='Stop!', command=stop)
button.pack(side=BOTTOM)
t = threading.Thread(None, bgt)
t.setDaemon(1) # Should really call stop() and t.join()
# on closing of the window for proper cleanup
t.start()
root.mainloop()
#-------------------------------------------------------------------
> > I am told what I want to do is
> > invalidate the GUI window every time an event occurs within it, whether it
> is a mouse click or the removal of a window that overlays it.
It sounds to me like you've been had:-) This makes no sense to me in the
context of Tkinter.
--
Niels Diepeveen
Endea automatisering
More information about the Python-list
mailing list