Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80399
| From | Akira Li <4kir4.1i@gmail.com> |
|---|---|
| Subject | Re: Moving a window on the screen |
| Date | 2014-11-08 19:35 +0300 |
| References | <545b321a$0$2396$426a34cc@news.free.fr> <mailman.15536.1415264262.18130.python-list@python.org> <545b3cd8$0$2306$426a34cc@news.free.fr> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15582.1415464608.18130.python-list@python.org> (permalink) |
"ast" <nomail@invalid.com> writes:
> Ok, thx, it works now with:
>
> import tkinter
> fen = tkinter.Tk()
>
> x=0
>
> def moveW():
> global x
> fen.geometry("200x200+%d+10" % x)
> x = x + 10
> if (x < 1200):
> fen.after(50, moveW)
>
> moveW()
In general, to avoid the start time "drift" [1], you could lock the
execution with a timer e.g., to move the window from left to right
*delta_x* pixels at a time every *period* ms [2]:
#!/usr/bin/env python3
from time import monotonic
from tkinter import Tk
def timer():
return int(monotonic() * 1000) # milliseconds
def call_repeatedly(period, function, *args):
root.after(period - timer() % period, call_repeatedly, period,
function, *args) # schedule the next call
function(*args)
def move(delta_x, max_x, width=200, x=[0]):
root.geometry("%dx50+%d+100" % (width, x[0]))
x[0] += delta_x # poor man's object
if x[0] > (max_x - width):
root.destroy() # exit
root = Tk()
period = 20 # call every *period* milliseconds
delta_x = 2 # how many pixels to move at a time
root.after(period - period % timer(), call_repeatedly, period,
move, delta_x, root.winfo_screenwidth())
root.mainloop()
[1]: http://stackoverflow.com/questions/8600161/executing-periodic-actions-in-python#comment26637231_8600301
[2]: http://stackoverflow.com/questions/24174924/how-to-run-a-function-periodically-in-python
Akira
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