TKinter + display of a shell command return

Eric Brunel eric_brunel at despammed.com
Wed Sep 8 17:49:57 CEST 2004


Yann.K wrote:
> Hello.
> 
> Using Tkinter, i would create a widget which display a shell command return.
> This return is long, and i would display a real time display (like with the
> tail -f commande on Linux)
> 
> I think to use the text widget.
> I have no problem to execute the command, but how to display, in a
> *real-time* fashion the shell retrun?

What is your problem here? Inserting at the end of the text and call the see 
method on the text widget to make sure the last line is displayed should be 
enough. An update_idletasks may also be needed to actually display something, 
but it depends on the architecture of your script, typically on whether you use 
threads or not.

A basic script doing what you want is:

--shell_output.py---------------------
import os
from Tkinter import *

root = Tk()
t = Text(root)
t.pack()

def go():
   p = os.popen("find . -name '*.py'", 'r')
   for l in p.xreadlines():
     t.insert(END, '%s\n' % l.rstrip())
     t.see(END)
     t.update_idletasks()

Button(root, text='Go', command=go).pack()

root.mainloop()
--------------------------------------

HTH
-- 
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com




More information about the Python-list mailing list