Apr-27-2020, 06:04 PM
I have a problem with a Combobox.
I want a Label to appear when a specific value is selected in the Combobox.
This is what I have tried, but it didn't work.
I want a Label to appear when a specific value is selected in the Combobox.
from tkinter import * from tkinter import ttk import turtle from math import cos,sin,tan,pi from threading import Event root = Tk() root.title("Mi app") stop = Event() def clear(): pen.clear() def graph (): chosen = box.get() # reset stop event, if it was already set stop.clear() pen.penup() angle = 0 theta = 0.01 steps = int ((100*pi/theta)) a = 1 b = 1 for t in range(0,steps): if stop.is_set(): break if chosen == "small": b = 2 if chosen == "big": b = 3 angle+=theta x=(cos(a*angle))*200 y=(sin(b*angle))*200 pen.goto(x,y) pen.pendown() canvas=turtle.Canvas(master=root, width=650, height=650) canvas.grid(row=0, column=0,columnspan=1, rowspan=20,padx=5,pady=5) pen=turtle.RawTurtle(canvas) pen.width(3) choose_label=Label(root, text="Choose what you want to draw:") choose_label.grid(column=1, row=1, columnspan=3, padx=5) box = ttk.Combobox (root, values = ["small", "big",]) box.grid(column = 1, columnspan=3, row = 2) box.current() graph_button=Button(root, text="Graph", command=graph) graph_button.grid(row=3,column=1,padx=5,pady=5) stop_button=Button(root, text="Stop", command=stop.set) stop_button.grid(row=3,column=2,padx=5,pady=5) clear_button=Button(root, text="Clear", command=clear) clear_button.grid(row=3,column=3,padx=5,pady=5) if box.get() == "small": chosen_label = Label(root, text="You choose 'small'") chosen_label.grid(column = 1, row = 4) if box.get() == "big": chosen_label = Label(root, text="You choose 'big'") chosen_label.grid(column = 1, row = 4) root.mainloop()How can I make a Label or any Widget appear when a specific value is selected in a Combobox?
This is what I have tried, but it didn't work.
if box.get() == "small": chosen_label = Label(root, text="You choose 'small'") chosen_label.grid(column = 1, row = 4) if box.get() == "big": chosen_label = Label(root, text="You choose 'big'") chosen_label.grid(column = 1, row = 4)