Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19311
| Date | 2012-01-23 22:57 -0500 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: problems with tkinter updates |
| References | <FxnTq.4267$5r2.3946@newsfe11.iad> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5005.1327377494.27778.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
problems with tkinter updates yves@zioup.com - 2012-01-23 18:09 -0700
Re: problems with tkinter updates Dave Angel <d@davea.name> - 2012-01-23 22:57 -0500
Re: problems with tkinter updates yves@zioup.com - 2012-01-23 23:47 -0700
Re: problems with tkinter updates Peter Otten <__peter__@web.de> - 2012-01-24 10:52 +0100
Re: problems with tkinter updates woooee <woooee@gmail.com> - 2012-01-24 09:50 -0800
Re: problems with tkinter updates Peter Otten <__peter__@web.de> - 2012-01-26 14:16 +0100
Re: problems with tkinter updates yves@zioup.com - 2012-01-27 07:02 -0700
Re: problems with tkinter updates yves@zioup.com - 2012-01-29 10:34 -0700
csiph-web