Passing keywords to methods in tkinter
Laura Creighton
lac at strakt.com
Tue Jan 21 15:01:10 EST 2003
> I'm having trouble passing arbitrary keywords to tkinter classes.
>
> When I call the class MyButton's init method from the App class, I get
> the error that the init method takes exactly 3 arguments, but 4 are
> provided.
>
> Thanks for any help.
>
> -- Stephen
>
>
> ########################################################
> from Tkinter import *
>
> class MyButton(Button):
> def __init__(self,parent,data,**kw):
> self.txt=data
> apply(Button.__init__, (self,parent),kw)
>
> def getValue(self):
> print self.txt
>
> class App:
> def __init__(self,parent):
> buttonDict = {'text':'some text', 'fg':'red'}
>
> # problem is here
> MyButton(parent,'1',buttonDict).grid(row=1,column=0)
> MyButton(parent,'2',buttonDict).grid(row=1,column=1)
> MyButton(parent,'3',buttonDict).grid(row=1,column=2)
You want **buttonDict here.
> if __name__=='__main__':
> root=Tk()
> app=App(root)
> root.mainloop()
>
> --
> http://mail.python.org/mailman/listinfo/python-list
Laura Creighton
More information about the Python-list
mailing list