Tkinter OptionMenu to show dropdown list box with options from List and dictionary values to users

plus2net
plus2net
4 هزار بار بازدید - 4 سال پیش - https://www.plus2net.com/python/tkinter-OptionMenu.php OptionMenu provides options to
https://www.plus2net.com/python/tkinter-OptionMenu.php OptionMenu provides options to the user to select one from the available list. It is also known as dropdown list box. We can display a list of options to the user for their selection. The options can be given by directly writing as the options while declaring the optionmenu. om1=tk.OptionMenu(my_w,options,'HTML','PHP','Phthon') We can use one list for storing the options as elements and unpack the same list to display the optionmenu. my_list=['Php','MySQL','Python','HTML'] options=tk.StringVar(my_w) options.set('languages') l1=tk.Label(my_w,text="Select One") l1.grid(row=1,column=1) om1=tk.OptionMenu(my_w,options,*my_list) While assigning the elements we have unpacked the list. We can use one dictionary values also as options of the option menu. my_dict1={1:'Fruits',2:'Colours',3:'Games',4:'Vehicles'} options=tk.StringVar(my_w) options.set(my_dict1[2]) l1=tk.Label(my_w,text="Select One") l1.grid(row=1,column=1) om1=tk.OptionMenu(my_w,options,*my_dict1.values())
4 سال پیش در تاریخ 1399/11/05 منتشر شده است.
4,074 بـار بازدید شده
... بیشتر