Overriding tkinter button methods - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Overriding tkinter button methods (/thread-5276.html) |
Overriding tkinter button methods - Lubik_ - Sep-26-2017 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. RE: Overriding tkinter button methods - metulburr - Sep-26-2017 You dont really need to override the button to do that. You can just create your own custom callback RE: Overriding tkinter button methods - Lubik_ - Sep-26-2017 I know, but in OOP - encapsulating is the most important character, so I really need class, no other solutions (witch I know)... RE: Overriding tkinter button methods - metulburr - Sep-26-2017 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. |