[Tutor] Tkinter
Hans Gubitz
gubitz@netcologne.de
Sun Dec 1 07:54:02 2002
My Tkinter.Button is an attribute in the class person. In the
Application I want to get the instance of person, button is belonging
to.
My workaround is the function holePerson. Is this the way you do it in
Python?
Hans
import Tkinter
from Tkconstants import *
class person:
def __init__(self,master,bild,r,c,callback):
self.bild = bild
self.button = Tkinter.Button(master,text=self.bild)
self.button.grid(row = r, column = c)
self.button.bind('<Button-1>',callback)
class Application:
def __init__(self, master):
frame = Tkinter.Frame(master)
frame.pack(fill=BOTH,expand=1)
bilder = ['baran.gif','bulenda.gif','flohe.gif','haemel.gif']
self.b00=person(frame,bilder[0],0,0,self.tausche)
self.b01=person(frame,bilder[1],0,1,self.tausche)
self.b02=person(frame,bilder[2],0,2,self.tausche)
self.b03=person(frame,bilder[3],0,3,self.tausche)
self.liste = [self.b00, self.b01, self.b02, self.b03]
def tausche(self,event):
self.aktuellerButton = event.widget
self.aktuellePerson = self.holePerson(self.aktuellerButton)
print self.aktuellePerson
def holePerson(self,button):
for l in self.liste:
if l.button == button:
return l
tk = Tkinter.Tk()
app = Application(tk)
tk.mainloop()
--
Hans Gubitz <gubitz@netcologne.de>