A tkinter kick-off

Mark Butterworth mrkbutty at mcmail.com
Wed Jun 2 19:58:28 EDT 1999


First of all thanks for the help.  The pointers to code everyone sent
certainly helped me, and the pipe capturing code will come in handy for
something else I've in mind.  However what I was after was something quick
and dirty (and simple) not to capture command output.  Please find my test
code below, once I span out the process function (it in turn will call many
more functions) it should be Ok.  Anyone got any suggestions for adding a
"Finished" message dialogue at the end and a method of keeping the listbox
scrolled to the end of the list would be appreciated (and save me hunting
through limited documentation).  Any pointers to decent documentation would
come in handy,  the tkinter tutorials are fine but of limited use as
reference.


from Tkinter import *
from tkmessagebox import *
import tkMessageBox,threading

class Logscreen:

    def __init__(self, master):

        frame = Frame(master)
        self.status = StringVar()
        self.status.set("My Test status")
        Label(frame, textvariable=self.status).pack()
        scrollbar=Scrollbar(frame, orient=VERTICAL)
        self.listbox=Listbox(frame, yscrollcommand=scrollbar.set)
        scrollbar.config(command=self.listbox.yview)
        scrollbar.pack(side=RIGHT, fill=Y)
        self.listbox.pack(side=LEFT, fill=BOTH, expand=1)
        frame.pack()

def process(root, listbox, status):
    for x in range(1,500):
        listbox.insert(END,'x is set to %d' % x)
        status.set('x is set to %d' % x)

    status.set('finished')
    root.destroy()

root = Tk()
root.title('My first Tk test')
root.resizable(1,0)
logscreen = Logscreen(root)
t=threading.Thread(target=process, args=(root,
logscreen.listbox,logscreen.status,))
t.start()
root.mainloop()


--

Regards, ]\/[r]{












More information about the Python-list mailing list