I am creating a Tkinter window with a 'for loop' so it can self-adjust if later on, I decide to add more questions. My issue is that I can't save the inputted value on the optionmenu. So far all I got was a list1 = ['', '', ''] while the Strg_var = [StringVar, StringVar, StringVar] and it prints only the blanks and the variables PY_numbers.
import tkinter as tk
from tkinter import *
LARGE_FONT = ("Arial", 12)
window=Tk()
def _save():
print(*list1, sep = ", ")
print(*Strg_var, sep = ", ")
Questionlist = ["A. Is A true? :", "B. Is B true? :", "C. Is C true? :"]
choices = ['-', 'Yes', 'No']
n = 0
Strg_var=[0]*len(Questionlist)
list1=[]
for n in range(len(Questionlist)):
Label(window, text=Questionlist[n], font = LARGE_FONT, background = "white").grid(row= n, column=0, columnspan=2, padx=10, pady = 10, sticky="W")
a = tk.StringVar(window)
OptionMenu(window, a, choices[0], *choices).grid(row = n, column=2, padx=10, sticky="WE")
list1.append(a.get())
tk.Button(window, text="Save", command = _save,width=18).grid(row=16, column=0, padx=10, pady=15, sticky="W")
window.mainloop()
Can someone help me to sort this out on how to save the optionmenu user selections into a list or any other way?
