有没有办法让选项菜单执行一系列不同命令中的命令?
from tkinter import *
#creates 2 windows
root = Tk()
popup = Toplevel()
#places frame in popup window
popup_frame = Frame(popup)
popup_frame.pack()
#4 functions, text is just placeholder for idea
def popup1(popup):
popup_frame.destroy()
popup_frame = Frame(popup)
label_popup1 = Label(popup_frame, text="unique textfor popup1")
popup_frame.pack()
label_popup1.pack()
def popup2(popup):
popup_frame.destroy()
popup_frame = Frame(popup)
label_popup2 = Label(popup_frame, text="unique text for popup2")
popup_frame.pack()
label_popup2.pack()
def popup3(popup):
popup_frame.destroy()
popup_frame = Frame(popup)
label_popup3 = Label(popup_frame, text="unique text for popup3")
popup_frame.pack()
label_popup3.pack()
def popup1(popup):
popup_frame.destroy()
popup_frame = Frame(popup)
label_popup4 = Label(popup_frame, text="unique text for popup4")
popup_frame.pack()
label_popup4.pack()
#2 option menus offering different selections
options1 = ["popup1", "popup2"]
variable1 = StringVar()
drop_title1 = StringVar(root)
#sets initial name for widget
drop_title1.set("Please Choose Options 1 Or 2")
dropdownmenu1 = OptionMenu(root, drop_title1, *options, command=lambda:func())
dropdownmenu1.place(x=10, y=10)
options2 = ["popup3", "popup4"]
variable2 = StringVar()
drop_title2 = StringVar(root)
drop_title2 .set("Please Choose Options 3 Or 4")
dropdownmenu2 = OptionMenu(root, drop_title2, *options, command=lambda:func())
dropdownmenu2.place(x=100, y=10)
root.mainloop()
因此,根框架中有 2 个不同的下拉菜单,如果您单击说选项 1,popup_frame 将被删除并替换为选项 1 的内容,然后从第二个下拉菜单中选择选项 4并且 popup_frame 的内容更改为选项 4 包含的内容?