I create a new Button object but did not specify the command option upon creation. Is there a way in Tkinter to change the command (onclick) function after the object has been created?
I create a new Button object but did not specify the command option upon
Share
Though Eli Courtwright’s program will work fine¹, what you really seem to want though is just a way to reconfigure after instantiation any attribute which you could have set when you instantiated². How you do so is by way of the configure() method.
¹ ‘fine’ if you use only the mouse; if you care about tabbing and using [Space] or [Enter] on buttons, then you will have to implement (duplicating existing code) keypress events too. Setting the
commandoption through.configureis much easier.² the only attribute that can’t change after instantiation is
name.