I'm new to Tkinter programming and am having trouble creating a
reusable button bar... I want to be able to feed my class a dictionary
of button names and function names, which the class will make.
My button bar is implemented a Frame subclass, which takes the button
dictionary as an argument and displays the buttons on the screen:
class OptionsBar(Fram e):
def __init__(self, buttonDict, parent=None)
Frame.__init__( self, parent)
parent.someFunc tion() # This works fine
for (name, command) in buttonDict.item s():
Button(self, text=name, command=command ).pack(side=TOP ,
fill=BOTH)
and then another Frame subclass, e.g. MyWindow, uses the bar as
follows:
self.buttonDict = {'Button1':'som eFunction',
'Button2':'othe rFunction'}
...
myBar = OptionsBar(pare nt=self, buttonDict=self .buttonDict)
myBar.pack(side =RIGHT)
...
def someFunction():
do button stuff
My problem is that the Button instances aren't calling the correct
functions when pressed. Is there anyway I get Button to call its
parent frame's parent frame's functions? I've tried using
self.buttonDict = {'Button1':'par ent.someFunctio n',
'Button2':'pare nt.otherFunctio n'}
but to no avail. Hope my explanations make sense.
Any suggestions?
Cheers
PAW
reusable button bar... I want to be able to feed my class a dictionary
of button names and function names, which the class will make.
My button bar is implemented a Frame subclass, which takes the button
dictionary as an argument and displays the buttons on the screen:
class OptionsBar(Fram e):
def __init__(self, buttonDict, parent=None)
Frame.__init__( self, parent)
parent.someFunc tion() # This works fine
for (name, command) in buttonDict.item s():
Button(self, text=name, command=command ).pack(side=TOP ,
fill=BOTH)
and then another Frame subclass, e.g. MyWindow, uses the bar as
follows:
self.buttonDict = {'Button1':'som eFunction',
'Button2':'othe rFunction'}
...
myBar = OptionsBar(pare nt=self, buttonDict=self .buttonDict)
myBar.pack(side =RIGHT)
...
def someFunction():
do button stuff
My problem is that the Button instances aren't calling the correct
functions when pressed. Is there anyway I get Button to call its
parent frame's parent frame's functions? I've tried using
self.buttonDict = {'Button1':'par ent.someFunctio n',
'Button2':'pare nt.otherFunctio n'}
but to no avail. Hope my explanations make sense.
Any suggestions?
Cheers
PAW
Comment