Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'chunk': 0.07; 'method,': 0.07; 'expected.': 0.09; 'loop.': 0.09; 'subject:problems': 0.09; 'tkinter': 0.09; 'def': 0.13; 'gui': 0.13; 'cc:addr:python-list': 0.15; "'\\n')": 0.16; 'apps.': 0.16; 'chance?': 0.16; 'manageable': 0.16; 'received:192.168.1.104': 0.16; 'subject:updates': 0.16; 'such.': 0.16; 'wrote:': 0.16; 'cc:no real name:2**0': 0.21; 'file,': 0.21; 'input': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'end,': 0.23; 'similarly': 0.23; 'cc:2**0': 0.25; 'there.': 0.25; 'pm,': 0.26; 'work,': 0.26; 'import': 0.27; "i'm": 0.27; 'beyond': 0.27; 'cc:addr:python.org': 0.29; 'sleep': 0.30; 'attach': 0.32; 'that,': 0.32; 'break': 0.32; "isn't": 0.32; "won't": 0.33; 'header:User-Agent:1': 0.33; 'there': 0.33; 'loop': 0.34; 'skip:# 10': 0.34; 'rather': 0.34; 'something': 0.35; 'help,': 0.35; 'window': 0.35; 'question': 0.35; 'comment': 0.35; 'similar': 0.36; 'but': 0.37; 'event': 0.38; 'some': 0.38; 'put': 0.38; 'subject:with': 0.38; 'received:192': 0.38; 'skip:o 20': 0.38; 'received:192.168.1': 0.39; 'missing': 0.39; 'subject:: ': 0.39; 'your': 0.61; 'chance': 0.62; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'concept,': 0.84; 'run?': 0.84 Date: Mon, 23 Jan 2012 22:57:34 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111109 Thunderbird/3.1.16 MIME-Version: 1.0 To: yves@zioup.com Subject: Re: problems with tkinter updates References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:zqDk/TjOglqSgXZGycSyXHOfYtSdjgXREeN9woy6acu ANNIbYQ1HocCZxo3Om7/cZlkSQGhzW40dJANnR7HGV1+iZr96U 0N2qQrW/sWqoXyFKKtkzRoXhOpcLZJ2XAMgknsyqI/p3I0jEQy bf+DqW7Vr+qrCqq5K0oKarP9/4leCS9VpTc6idItJwYpIujgPG krdk6egffEECyVv1Lj8XJbrMJHe7umvQ8cwX/7rK2I5/jJ6f/W oGMVRuTNpnddyUeLRnuilwwKun5abwEqunItWovQ+3bNQ4/HI/ FUAscSOIjtbJTdq3b0EWSewBR2F9ho7DwjmbcYTxQ5OSxm/8g= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name 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: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327377494 news.xs4all.nl 6909 [2001:888:2000:d::a6]:54951 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19311 On 01/23/2012 08:09 PM, 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? > You have it backward. The question is not what you do inside your loop to give tk a chance, but rather what do you do to make tk give you a chance. tk doesn't "start" till you make the mainloop() method call, and once you call that method, it won't return till the program is exiting. So, forget about input statements inside some loop. Input isn't a gui concept, it's for console apps. Gui apps use dialog boxes and such. Similarly sleep(). mainloop() will sleep, when there are no events in its queue. If you want to do work, break it into manageable chunks, and attach each chunk to some event that tk will fire. Beyond that, I cannot help, for I don't know tkinter. But all gui's are similar at this level of detail. -- DaveA