Sep-04-2022, 09:07 PM
Please see the thread Namespace flooding with * imports
If your intention is to make a special version of a
Subclass
I would leave the parent to decide how the buttons are located.
specialized_btn.py
If your intention is to make a special version of a
tk.Button
that you set some attributes and then use that button in various places.Subclass
tk.Button
and then you can use it in place of a normal tk.Button
,I would leave the parent to decide how the buttons are located.
specialized_btn.py
import tkinter as tk class SpecializedButton(tk.Button): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # your sepecialized code here self.config(bg="Red")main.py
import tkinter as tk from specialized_btn import SpecializedButton class MainFrame(tk.Frame): def __init__(self, *args, **kwargs): super().__init__(*args, *kwargs) specialized_button = SpecializedButton(self, text="B1") specialized_button.pack() def main(): app = tk.Tk() app.title("Main Window") app.geometry("600x400") app.eval("tk::PlaceWindow . center") main_frame = MainFrame(app) main_frame.pack() app.mainloop() if __name__ == "__main__": main()