A friend found that the optionmenu component created in the Tkinter module was successful, but in the TTK module, when you click other options, the first option disappears and will never appear again.
The code under the TTK module is:
from tkinter import * root=Tk() var=StringVar() tuple_op=('car','Bicycle','aircraft') op1=OptionMenu(root,var,*tuple_op) op1.pack() root.mainloop()
Analyze the cause of the problem:
Under the TTK module, the syntax for creating the optionmenu component has changed, but many friends have not found it. The syntax under TTK is:
The third parameter in Tkinter module does not need to be written. The default is item 1 as the default option at startup.
Therefore, if the above code is changed to the following code, there will be no problem. (just change the code to create the component)
from tkinter import * from tkinter.ttk import * root=Tk() root.title('aying7.com') var=StringVar() tuple_op=('car','Bicycle','aircraft') op1 = OptionMenu(root,var,tuple_op[0],*tuple_op) op1.pack() root.mainloop()
Operation diagram:
source: Typing.news
Link to this article: http://typing.news/post/3.html
Good Luck To You!