Gentlemen,

I don't consider myself a rank beginner (I did take a shower this week), but I've been beating my brains out over this for the past week.

I'm writing this GUI app (Tkinter). Just about everything is done (all the nuts,bolts, and the occasional nail. Now Im trying to code a simple status window to let the dumb user (me) know what's going on behind the curtain. The idea is, the application calls the subroutine, the subroutine pops open a frame and print some text in it, then returns control back to the main app - leaving the frame/text visible. Then, the app calls the subroutine and *updates* the frame, so you end up with a growing list of notices...(basically, I'm working with a variable set of files, and it's convenient to know which is being operated on)

I've ripped code from Mark Lutz's book (3rd edition), from Welch's book (also 3rd edition), and from around the net. It seems to me that I'm missing something obvious when it comes to self.update. The subroutine works as advertised the first time through, but one the window is open and the text displays, the app stops - unless I close the window. Of course, then everything works until the NEXT message is displayed.

Sure, I could add a button and work from that, but I don't *WANT* to - the idea is a (more or less) continuous flow of information that I can scroll through if need be.

As you can see from the sample code below, I'm using the Text widget instead of Message. I had a reason for that when I started this nightmare, but I'm not wedded to it.

Any assistance from anybody would be much appreciated.

Thanks in advance!

Erik

-----------------------

from Tkinter import *

data={}
data[4,9]="you are here"
data[4,10]=0
msg=1
x={}

def loop():
   global x
   x[1]=0
   while x[1]<10:
       messages(x)
       print "howdee"
       x[1]=x[1]+1

def messages(msg):
   class MESSAGES(Frame):
       def __init__(self,parent=None,text='', file=None):
           Frame.__init__(self,parent)
           self.pack(expand=YES,fill=BOTH)
           self.makewidgets()
           self.message(text)
           self.update()
def makewidgets(self):
           sbar=Scrollbar(self)
           a=Text(self,relief=RAISED)
           sbar.config(command=a.yview,bg='#fcfcfc')
           a.config(yscrollcommand=sbar.set,bg='#f0f0f0')
           sbar.pack(side=RIGHT,fill=Y)
           a.pack(side=LEFT,expand=YES,fill=BOTH)
           self.a=a
           data[4,10]=1
def message(self,text):
           self.a.insert(END,text)
           self.a.focus()
           return self.a.get('35.2',END+'-1c')

   if __name__=='__main__':
       root=Tk()
       MESSAGES(text=data[4,9]).mainloop()
       return
loop()

I've tried this small mod, just now, but it *really* breaks things the second time through:


   class MESSAGES(Frame):
       def __init__(self,parent=None,text='', file=None):
           Frame.__init__(self,parent)
           self.pack(expand=YES,fill=BOTH)
           if data[4,10]==0:
               self.makewidgets()
           self.message(text)
           self.update

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to