Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80323

Re: Moving a window on the screen

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'root': 0.05; 'intermediate': 0.07; 'tkinter': 0.07; 'callback': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'def': 0.12; 'gui': 0.12; 'ast': 0.16; 'invocation': 0.16; 'itself,': 0.16; 'loop.': 0.16; 'range(0,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:screen': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'initial': 0.24; 'script': 0.25; 'pass': 0.26; 'header:X-Complaints-To:1': 0.27; 'chris': 0.29; 'thus': 0.29; "doesn't": 0.30; 'work.': 0.31; 'usually': 0.31; 'run': 0.32; 'another': 0.32; 'subject:the': 0.34; 'except': 0.35; 'but': 0.35; 'window': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'back': 0.62; 'such': 0.63; 'skip:n 10': 0.64; 'dont': 0.67; '500': 0.70; 'consequently': 0.84; 'milliseconds': 0.84; 'subject:Moving': 0.84; 'state.': 0.95
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Moving a window on the screen
Date Thu, 06 Nov 2014 10:15:20 +0100
Organization None
References <545b321a$0$2396$426a34cc@news.free.fr>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd941a.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
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.15537.1415265339.18130.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415265339 news.xs4all.nl 2878 [2001:888:2000:d::a6]:56932
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80323

Show key headers only | View raw


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


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