我星期一开始用Python编程.我很高兴学习它.但是我很难理解如何在tkinter菜单之间切换时避免递归!我确信这是一个非常基本的问题,我感谢你容忍我对这个问题的无知,但我一直无法在其他地方找到答案.
我现在正在做的是,最终给我错误:RuntimeError:调用Python对象时超出了最大递归深度
这是我目前使用的模式.更新:下面的代码现在是一个完整的,孤立的副本,再现了我面临的问题!:d
from tkinter import *
def mainmenu():
global frame, root
frame.destroy()
frame = Frame()
frame.pack()
button1 = Button(frame, text="anothermenulikethis", command = anothermenulikethis)
button2 = Button(frame, text="anothermenulikethis", command = anothermenulikethis)
button3 = Button(frame, text="mainmenu", command = mainmenu)
button1.pack(side=LEFT)
button2.pack(side=LEFT)
button3.pack(side=LEFT)
root.mainloop()
def anothermenulikethis():
global frame, root
frame.destroy()
frame = Frame()
frame.pack()
button1 = Button(frame, text="mainmenu", command = mainmenu)
button2 = Button(frame, text="mainmenu", command = mainmenu)
button3 = Button(frame, text="anothermenulikethis", command = anothermenulikethis)
button1.pack(side=LEFT)
button2.pack(side=LEFT)
button3.pack(side=LEFT)
root.mainloop()
root = Tk() …Run Code Online (Sandbox Code Playgroud)