0

I cannot get the StringVar class to work in my OptionMenu widget, it just appears blank in the OptionMenu. This works on my main window but not this pop-up window here is my code.

def create_new():
    new = tk.Tk()
    new.geometry('300x400')
    new.title('Create New Project')

    l1 = Label(new, text = 'Name of the Project: ', font = ('Arial', 13))
    name = Entry(new)

    menu = StringVar()
    menu.set('Type of Project')
    drop = OptionMenu(new, menu, 'Type of Project', 'Photo Editing', 'lol')

    l1.pack()
    name.pack()
    drop.pack()

Note: I am creating another tkinter window for this.

The optionmenu appears like this The option menu is just empty

Dodu
  • 109
  • 2
  • 8
  • maybe use names arguments in `OptionMenu` - maybe you assign values for wrong arguments. – furas Apr 03 '22 at 13:42
  • 1
    do you create two `Tk()` (and two `mainloop()`)? Program should have only one `Tk()` (as main window) and only one `mainloop()` and other windows should be created with `Toplevel()`. And it may be good to put parent in `StringVar(new)` like in other objects. If you have two `Tk()` then some `StringVar`, `IntVar` may be assigned to wrong window and they may have problem to correctly work with widgets. – furas Apr 03 '22 at 13:44
  • Thanks for telling me the the toplevel, I haven't put to mainloop() – Dodu Apr 03 '22 at 14:14
  • @furas Thanks it works in an instant now it is working – Dodu Apr 03 '22 at 14:16

0 Answers0