0

in the following code i want to be able to change the value of the combo box and immediately have a labels and entry boxes put on the form. the code that i tried using is not working as intended but i am not getting any errors.

nb = ttk.Notebook(root)
nb.grid(row=1, column=0, columnspan=50, rowspan=49, sticky='NESW')

page1 = ttk.Frame(nb, style='body.TFrame')
nb.add(page1, text='Create Tasks')

specify = StringVar()

site_lbl = Label(page1, text="Site", bg='#1C2833', fg='#FDFEFE', font=("Helvetica", 14))
site_lbl.place(x=5, y=20)
site_combo = ttk.Combobox(page1, width=15, values=[
    'YeezySupply'
])
site_combo.place(x=55, y=25)


def add_store_options_ys():
    if specify.get() == 'YeezySupply':
        stylecode_lbl = Label(page1, text="Site", bg='#1C2833', fg='#FDFEFE', font=("Helvetica", 14))
        stylecode_lbl.place(x=5, y=20)
        stylecode_entry = Entry(page1, width=15, bg='#1C2833', fg='#FDFEFE', font=("Helvetica", 8))
        stylecode_entry.place(x=55, y=25)


specify.trace_variable("w", add_store_options_ys)


I know i could do this by using a button to then call the function but i dont want to use a button and i want it to check automatically and then update the page with the labels and entry box.

1 Answers1

0

You haven't associated the variable with the combobox. Therefore the variable doesn't change when you select a value, and thus, the trace doesn't fire.

site_combo = ttk.Combobox(..., textvariable=specify)

You will then have the problem that the function doesn't accept the values being passed by the variable trace. For more information see What are the arguments to Tkinter variable trace method callbacks?

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • hi sorry to come back after marking this as the answer but i am still having trouble with this. I saw an example somewhere where once someone used the trace method their code worked mine. Mine is fairly similar to it except they dont have code to make labels in it. Im not sure if i cannot use labels inside of the function that the trace option leads too but i am stuck and lost, lol. If you have any suggestions that would be great! –  Jan 11 '20 at 05:12
  • 1
    @mferraro: you can use labels. – Bryan Oakley Jan 11 '20 at 06:37