Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'else:': 0.03; 'sys': 0.05; 'none:': 0.07; 'expected.': 0.09; 'none)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:problems': 0.09; 'tkinter': 0.09; 'def': 0.13; "'\\n')": 0.16; 'chance?': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'subject:updates': 0.16; 'wrote:': 0.16; 'file,': 0.21; 'end,': 0.23; 'from:addr:web.de': 0.23; 'there.': 0.25; 'import': 0.27; "i'm": 0.27; 'sleep': 0.30; 'to:addr:python-list': 0.33; 'loop': 0.34; 'skip:# 10': 0.34; 'root': 0.34; 'header:X-Complaints-To:1': 0.34; 'something': 0.35; 'window': 0.35; 'comment': 0.35; 'received:org': 0.37; 'some': 0.38; 'put': 0.38; 'subject:with': 0.38; 'skip:o 20': 0.38; 'missing': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'chance': 0.62; 'run?': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: problems with tkinter updates Date: Tue, 24 Jan 2012 10:52:52 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084b9f1.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 73 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327398783 news.xs4all.nl 6980 [2001:888:2000:d::a6]:35583 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19335 yves@zioup.com wrote: > > I'm missing something about tkinter updates. How can I give tkinter a > chance to run? > > Here's some code: > > import time > import tkinter > import tkinter.scrolledtext > > tk = tkinter.Tk() > f = tkinter.Toplevel(tk) > st = tkinter.scrolledtext.ScrolledText(f) > st.pack() > > > > def update(): > print('updating') > st.see(tkinter.END) > tk.after(1000, update) > > > input('hit enter to start') > update() > f = open('/etc/services') > > for line in f: > st.insert(tkinter.END, line + '\n') > print('got it') > #time.sleep(5) > input('more?') > > input('finished?') > > > > > When I do this (input('more?'), it works as expected. If I comment that > line out, then the program reads the entire file, then update the window > right at the end, even if I put a sleep in there. What can I do inside the > loop to give tk a chance? Have update() (renamed to read_more() in my code) do the reading: import sys import tkinter import tkinter.scrolledtext root = tkinter.Tk() text_window = tkinter.Toplevel() text = tkinter.scrolledtext.ScrolledText(text_window) text.pack() infile = open(sys.argv[1]) def read_more(): line = next(infile, None) if line is not None: text.insert(tkinter.END, line) root.after(100, read_more) else: text.insert(tkinter.END, "\nThat's all folks", "looney") text.tag_configure("looney", foreground="RED") text.see(tkinter.END) read_more() root.mainloop()