if i choose a value from first combobox menu, then the next combobox menu will show only values that inside the first selected combobox value category.
and as soon as i click second combobox menu i want my result "Hello" as a output as a text label.
The code is as below-
import tkinter as tk
Classid = ["A", "B", "C"]
subclassid = [["X", "Y", "Z"],["X", "Y", "Z"], ["X", "Y", "Z"]]
root = tk.Tk()
canvas = tk.Canvas(root, height = 500, width = 500, bg='white')
canvas.pack()
tkClassid = tk.StringVar(root)
tkClassid.set("Choose")
tksubid = tk.StringVar(root)
tksubid.set('Drug Class')
popupMenu1 = tk.OptionMenu(canvas, tkClassid, Classid)
popupMenu1.pack()
popupMenu2 = tk.OptionMenu(canvas, tksubid, [])
popupMenu2.pack()
def change_dropdown(*args):
print("Chosen Class " + tkClassid.get())
for i in range(len(Classid)):
if tkClassid.get() == Classid[i]:
popupMenu2["menu"].delete(0, "end")
for item in subclassid[i]:
popupMenu2['menu'].add_command(label=item, command=tk_setit(tksubid, item))
tkClassid.trace('w', change_dropdown)
def resultout():
myLabel = Label(root, text=clicked.get()).pack()
if x=='A' and y=='X':
print('Hello')
clicked = StringVar(root)
myButton= Button(root,text='Result', command=resultout).pack()
root.mainloop()