My code:
import tkinter as tk
from tkinter import ttk
win = tk.Tk()
def assign():
value = number.get()
if value == 'op1':
label = tk.Label(win, text = number)
label.grid(column = 1, row = 0)
number = tk.StringVar()
box = ttk.Combobox(win, textvariable = number, state = 'readonly')
box['values'] = ('op1','op2','op3')
box.set('op2')
box.grid(column = 0, row = 0)
box.bind('<<ComboboxSelected>>', assign())
win.mainloop()
Explanation: this is how I think my program works.
box, which is the Combobox, has assigned a textvariable named number that, I suppose, takes the values of box, that is, ('op1', 'op2', 'op3'). box is then binded to a subprogram called assign() which will retrieve the value of number and set it equal to value. If value is equal to 'op1', the subprogram will create and grid a label called label that will display the text 'Hello'. Unfortunately, this doesn't work. In other words, my objective is to, when the user selects one of the values given in box['values'], assign() runs and, If the codition is met, display label.
Output:
As you can see, even though I selected 'op1', label isn't displayed next to box.
