Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OptionMenu won't show the first option when clicked (Tkinter)

I added a OptionMenu widget to my code, and assigned a list as it's options. This is how it is:

z = StringVar()   
z.set(userList[0])    
usersOption = OptionMenu(frame1, z, *userList)#, command=changeUser)
usersOption.pack(side=RIGHT, padx=3)

Now, I reckon it would show all the options in said list. As so:

Option 1 \/ <-- the box with the selected option
Option 1 }\__the options that show on click
Option 2 }/

but it actually only shows the second option, and when I choose it there is, basically, no way back, if I click the box again it keeps only showing option 2 and I can't change it even with the up and down keys. I tried looking for solutions, but I got nowhere, so I'm starting to think it is the default operating way of the widget, but I found nothing to show me how to solve it in the documentation I read.
P.S.: I'm using Python 3.3

like image 314
AugustoQ Avatar asked May 13 '13 02:05

AugustoQ


1 Answers

I had the same problem and it was driving me mad, so i looked in the source. I think the issue is that the 3rd constructor argument is the default value. If you don't specify it before *userList, it looks like it takes the first item as the default value. A real fix would be something like:

z = StringVar()   
z.set(userList[0])    
usersOption = OptionMenu(frame1, z, userList[0] ,*userList)#, command=changeUser)
usersOption.pack(side=RIGHT, padx=3)
like image 183
Will Munn Avatar answered Oct 27 '22 00:10

Will Munn