Python Forum
[Tkinter] eport selections to dic
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] eport selections to dic
#1
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 ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] Help Iterating through to read comboBox Selections Extra 3 1,542 Aug-01-2022, 06:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020