May-24-2019, 12:43 PM
When you inherit from another class you don't call it
simply change
Here is an example of your previous post code with the forms as separate classes
simply change
class Window(tk.Tk()):to
class Window(tk.Tk):and your code will work.
Here is an example of your previous post code with the forms as separate classes
import tkinter as tk class MainFrame(tk.Tk): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.form1 = Form1(self, background="pink") self.form2 = Form2(self, background="lightblue") self.form2.btn.bind("<Button-1>", self.on_form2_button) def on_form2_button(self, event): print("form2 button clicked") class Form1(tk.Frame): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.pack(fill=tk.BOTH, expand=1) lbl = tk.Label(self, text="Form1") lbl.pack(expand=1) class Form2(tk.Frame): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.pack(fill=tk.BOTH) self.btn = tk.Button(self, text="Form2") self.btn.pack() if __name__ == "__main__": main_frame = MainFrame() main_frame.mainloop()