[Tutor] Exchanging window data
Glen Barnett
glenbar@gte.net
Thu, 10 Oct 2002 14:44:42 -0700
I'm writing a script to use any number of windows and I'm interested in
exchanging data among them. In the sample I have here the main window passes
a method name "hitCntl" and a variable name "self.messag" to the new windows
when they are created using the class Frm1. When a button is pressed a
message is added to the variable and the method is called. Is this the
proper technique? What other ways are there? I noticed if I use
self.messag=[] in "hitCntl" instead of self.messag.pop(0) to clear it then
the messages no longer work even though the name is the same.
Thanks
Glen
#
from Tkinter import *
class Frm1:
def __init__(self,frame,mess,note,name):
self.name1=name
self.message=mess
self.note1=note
self.bb=Button(frame,text="Hello",command=self.b2c)
self.bb.pack()
def b2c(self):
self.message.append(self.note1)
self.name1()
class MAIN1:
def __init__(self,frame):
self.messag=[]
for x in range(25):
w2=Toplevel()
tm= "Hello from %d" %x
Frm1(w2,self.messag,tm,self.hitCntl)
def hitCntl(self):
print "Redirected"
print self.messag
self.messag.pop(0)
if __name__ =="__main__":
root=Tk()
cf=MAIN1(root)
root.mainloop()