Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19335
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: problems with tkinter updates |
| Date | 2012-01-24 10:52 +0100 |
| Organization | None |
| References | <FxnTq.4267$5r2.3946@newsfe11.iad> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5022.1327398783.27778.python-list@python.org> (permalink) |
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()
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