就像有一个下拉菜单中的大洲名称,显示与所选大洲相关的国家名称一样。如何使用Tkinter实现此目标?我在第一个下拉菜单中有大洲列表,以及所有与大洲相关的国家列表。当选择大洲1时,我想显示country_11,country_12等国家,对于其他大洲也是如此。
以下是我正在处理的代码片段 -
import tkinter as tk
from tkinter import ttk
from tkinter import *
root = tk.Tk()
root.geometry('500x500')
#Label to Continent
label_1 = tk.Label(root, text="Select the Continent", font = (8), bg = '#ffe1c4')
label_1.place(x = 120, y = 220)
# Continent selection - drop down
optionList1 = ["Continent1", "Continent2","Continent3"]
dropVar1 = StringVar()
dropMenu1 = ttk.OptionMenu(root, dropVar1 , *optionList1)
dropMenu1.place(x = 300, y = 220)
#Label to Select Country
label_2 = tk.Label(root, text="Select the Country ", font = (8), bg = '#ffe1c4')
label_2.place(x = 120, y = 250)
# Country name selection - drop down
optionList2 = ["Country_11", "Country_12", "Country_21","Country_22","Country_31","Country_32"]
dropVar2 = StringVar()
dropMenu2 = ttk.OptionMenu(root, dropVar2, *optionList2)
dropMenu2.place(x = 300, y = 250)
root.mainloop()
希望有解决方案,因为我不知道Tkinter中的OptionMenu可以具有哪些属性。谢谢!