Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80323
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Moving a window on the screen |
| Date | 2014-11-06 10:15 +0100 |
| Organization | None |
| References | <545b321a$0$2396$426a34cc@news.free.fr> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15537.1415265339.18130.python-list@python.org> (permalink) |
ast wrote:
> Why the following program doesn't work ?
>
> for x in range(0, 100, 10):
> fen.geometry("200x200+%d+10" % x)
> time.sleep(0.5)
>
>
> where fen is a window (fen = Tk())
>
> The fen window goes from it's initial location to the last one
> but we dont see all the intermediate steps
As Chris says, using sleep() with a gui program usually doesn't work. While
the script is sleeping the event loop doesn't run and consequently the user
will not see any updates of the program's state.
Instead of sleeping you have to schedule events that trigger a callback and
then go back to the event loop. Such a callback may schedule another
invocation of itself, thus giving you the desired effect:
import tkinter as tk
root = tk.Tk()
xpositions = iter(range(0, 100, 10))
def move_next():
try:
x = next(xpositions)
except StopIteration:
pass
else:
root.geometry("200x200+%d+10" % x)
root.after(500, move_next) # have tkinter call move_next again
# in about 500 milliseconds
root.after_idle(move_next)
root.mainloop()
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Moving a window on the screen "ast" <nomail@invalid.com> - 2014-11-06 09:32 +0100
Re: Moving a window on the screen Chris Angelico <rosuav@gmail.com> - 2014-11-06 19:57 +1100
Re: Moving a window on the screen "ast" <nomail@invalid.com> - 2014-11-06 10:18 +0100
Re: Moving a window on the screen Akira Li <4kir4.1i@gmail.com> - 2014-11-08 19:35 +0300
Re: Moving a window on the screen Terry Reedy <tjreedy@udel.edu> - 2014-11-08 13:40 -0500
Re: Moving a window on the screen Akira Li <4kir4.1i@gmail.com> - 2014-11-08 23:31 +0300
Re: Moving a window on the screen Terry Reedy <tjreedy@udel.edu> - 2014-11-12 15:06 -0500
Re: Moving a window on the screen Peter Otten <__peter__@web.de> - 2014-11-06 10:15 +0100
Re: Moving a window on the screen Terry Reedy <tjreedy@udel.edu> - 2014-11-06 04:25 -0500
csiph-web