Я строю небольшую программу, где разные части кода будут вызывать один объект в разное время. Я хотел бы попытаться заставить его вызывать предыдущий кадр назад вместо дублирования фактического кода несколько раз. Вот часть моего кода, если вам нужен пример:Как я могу сделать программу tkinter перейти к предыдущему кадру?
#Console Menu
class consoleMenu(tk.Frame):
#Initialize
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
#Setups
consoleGuideLabel = ttk.Label(self, text = "Console Guide", font = LARGE_FONT)
consoleItemInfoButton = ttk.Button(self, text = "Console Item Info", command = lambda: controller.show_frame(consoleItemInfo))
consoleVersionButton = ttk.Button(self, text = "Console Version History", command = lambda: popupmsg ("Not supported just yet!"))
consoleMainMenuButton = ttk.Button(self, text = "Main Menu", command = lambda: controller.show_frame(StartPage))
#Placement
consoleGuideLabel.pack(pady = 10, padx = 10)
consoleItemInfoButton.pack()
consoleVersionButton.pack()
consoleMainMenuButton.pack()
Теперь это та часть, которая вызывается в несколько раз разными кадрами.
#Air - MCPE, PC, Xbox
class mc_air(tk.Frame):
#Initialize
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
#Item Info
text_file = open("minecraft_air.txt", "r")
file = text_file.read()
text_file.close()
#Setups
airLabel = ttk.Label(self, text = "Minecraft - Air - 1", font = LARGE_FONT)
airInfo = ttk.Label(self, text = file, font = NORMAL_FONT)
exitButton = ttk.Button(self, text = "Return to Menu", command = lambda: controller.show_frame(StartPage))
#Placement
airLabel.pack(pady = 10, padx = 10)
airInfo.pack()
exitButton.pack()
Где он говорит:
exitButton = ttk.Button(self, text = "Return to Menu", command = lambda: controller.show_frame(StartPage))
Я хотел бы быть в состоянии заменить StartPage с командой, чтобы перейти к предыдущему окну.