How to populate TkinterMenu parameter with items in a list

โ€œI want to populate the options menu in Tkinter with elements from different lists, how to do this? The code below treats the entire list as one element in the menu. I tried to use the for operator to scroll through the list, but it gave me the valueโ€œ a โ€several times.

from Tkinter import * def print_it(event): print var.get() root = Tk() var = StringVar() var.set("a") lst = ["a,b,c,d,e,f"] OptionMenu(root, var, lst, command=print_it).pack() root.mainloop() 

I want to pass a variable to this function, but I get a syntax error for the second line:

 def set_wkspc(event): x = var.get() if x = "Done": break else: arcpy.env.workspace = x print x 
+4
source share
1 answer

lst in your code there is a single line list.

Use a list with several menu names and specify them as follows:

 .... lst = ["a","b","c","d","e","f"] OptionMenu(root, var, *lst, command=print_it).pack() .... 
+9
source

Source: https://habr.com/ru/post/1496830/


All Articles