I'm trying to make a Python GUI using tkinter
, and I need a menu item that opens another copy of the main window. I tried to do the following code, and when I ran the program, it froze for a bit, then opened a large number of windows. The last error message printed is below.
I have two questions.
- How can I accomplish the task of making the "New" button open a new window and instance of the
TheThing
class? (In IDLE,File > New File
has the behavior I'm seeking.) Why is this error happening?
RecursionError: maximum recursion depth exceeded while calling a Python object
My code:
import tkinter as tk
class TheThing:
def __init__(self, root):
root.option_add('*tearOff', False)
menubar = tk.Menu(root)
root.config(menu = menubar)
file = tk.Menu(menubar)
menubar.add_cascade(menu = file, label = "File")
file.add_command(label = 'New', command = doathing())
def doathing():
thing1 = tk.Tk()
thing2 = TheThing(thing1)
def main():
win = tk.Tk()
do = TheThing(win)
win.mainloop()
if __name__ == '__main__': main()
Places I've already looked for answers:
This question seemed like it was having a very similar problem. I may be able to study that and find a solution, but I still won't understand the problem.
This question was about recursion, python, and tkinter, but seemed to be about more the
after
thing.