Dec-10-2020, 04:30 AM
(This post was last modified: Dec-10-2020, 04:30 AM by deanhystad.)
You should fix the syntax error. The error is not this line "m = Main(root)".
Here are a couple of methods that receive a widget as an argument and perform some action on the widget.
Here are a couple of methods that receive a widget as an argument and perform some action on the widget.
import tkinter as tk class MyWindow: def __init__(self, root): frame = tk.Frame(root) frame.pack(expand=True, fill=tk.BOTH) label = tk.Label(frame, text="Press the Button") label.pack(expand=True, fill=tk.BOTH, padx=5, pady=5) button = tk.Button(frame, text="This is the Button") button.config(command=lambda:self.button_pressed(button, label)) button.pack(expand=True, fill=tk.BOTH, padx=5, pady=5) quitbn = tk.Button(frame, text="Quit", command=lambda:self.quit(root)) quitbn.pack(expand=True, fill=tk.BOTH, padx=5, pady=5) def button_pressed(self, button, label): label['text'] = 'The button was pressed' button['state'] = tk.DISABLED def quit(self, window): print('Quitting') window.destroy() root = tk.Tk() root.geometry('200x200') MyWindow(root) root.mainloop()