Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80400
| Path | csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.05; 'root': 0.05; 'python3': 0.07; 'tkinter': 0.07; '[1]:': 0.09; '[2]:': 0.09; 'e.g.,': 0.09; 'exit': 0.09; 'function,': 0.09; 'pixels': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'worse': 0.09; 'def': 0.12; 'jan': 0.12; '*args):': 0.16; 'arbitrary.': 0.16; 'fine.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:screen': 0.16; 'tk()': 0.16; 'win7': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'second': 0.26; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'code': 0.31; 'writes:': 0.31; 'period': 0.33; 'skip:# 10': 0.33; 'subject:the': 0.34; 'could': 0.34; 'next': 0.36; 'half': 0.37; 'wrong': 0.37; 'window': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'hardly': 0.84; 'milliseconds': 0.84; 'received:fios.verizon.net': 0.84; 'subject:Moving': 0.84; 'received:108': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Moving a window on the screen |
| Date | Sat, 08 Nov 2014 13:40:53 -0500 |
| References | <545b321a$0$2396$426a34cc@news.free.fr> <mailman.15536.1415264262.18130.python-list@python.org> <545b3cd8$0$2306$426a34cc@news.free.fr> <87oash8xbd.fsf@gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-108-16-203-145.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
| In-Reply-To | <87oash8xbd.fsf@gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15583.1415472071.18130.python-list@python.org> (permalink) |
| Lines | 75 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1415472071 news.xs4all.nl 2939 [2001:888:2000:d::a6]:47033 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:80400 |
Show key headers only | View raw
On 11/8/2014 11:35 AM, Akira Li wrote:
> "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],
which is hardly noticeable
> 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]:
On my Win7 machine, your complicated code is much worse as it causes the
window to jump about every half second
> #!/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,
The '- timer() % period' 'correction' is wrong when not 0 as it causes
jumps.
> 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,
'period % timer()' is nonsensical as timer() is arbitrary. It will
typically be 0 anyway. 'after(0, ...)' works fine.
> 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
>
--
Terry Jan Reedy
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