Python Forum

Full Version: Overriding tkinter button methods
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I need to create new class NButton(tkinter.Button) in witch I want to override constructor and event onclick.
I want make some extra action in onclick event. Can some help me? I need it exactly as new object no another solutions.
Thank you.
You dont really need to override the button to do that. You can just create your own custom callback
I know, but in OOP - encapsulating is the most important character, so I really need class, no other solutions (witch I know)...
from tkinter import *

class MyButton(Button):
    def __init__(self, *args, **kwargs):
        Button.__init__(self, *args, **kwargs)
        self['bg'] = 'red'

root = Tk()
my_button = MyButton(root, text='red button').pack()
root.mainloop()
and im not even sure what their button_down method is named to even override it.