Passing keywords to methods in tkinter

Stephen Boulet stephen.boulet at motorola.com
Tue Jan 21 14:29:36 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)

if __name__=='__main__':
	root=Tk()
	app=App(root)
	root.mainloop()





More information about the Python-list mailing list