Python Forum

Full Version: eport selections to dic
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i want to export the selections from dropdown to dic like:
ANSWER_KEY = {0:3,1:1,2:6,3:4,4:4,5:4,6:4,7:4,8:4,9:4}
i try to used:
ANSWER_KEY = OPTIONS[var.get()]
but it not work.
the code:
import tkinter as tk

# --- functions ---

def on_button():
   for i, var in enumerate(o_vars):
 #      print('OptionMenu {}: {}'.format(i, OPTIONS[var.get()]))
       ANSWER_KEY = OPTIONS[var.get()]
   print()


[i]# --- main ---

#OPTIONS = ["Script 1","Script 2","Script 3","Script 4","Script 5"]
OPTIONS = {
   'a': '4',
   'b': '3',
   'c': '2',
   'd': '1',
   'e': '0',
}

root = tk.Tk()

# --- OptionMenu ---

tk.Label(root, text='text', bg='#aaa').pack(fill='x')

o_vars = []

for i in range(10):
   var = tk.StringVar(value='- select -')
   o_vars.append(var)
   o = tk.OptionMenu(root, var, *OPTIONS)
   o.pack()



# --- others ---

b = tk.Button(root, text='OK', command=on_button)
b.pack(fill='x')

root.mainloop()[/i]
please how i can create dic from this dropdown ?