I'm attempting to use tkinter's .grid organization to make a comparative program, comparing qualities from different items in a list. My goal is to have a OptionMenu with every item listed in the first column of every row, and then to populate the rest of the row,s cells based on the selected item from the OptionMenu. Later I'll be adding more cells onto the right side to compare qualities, but I am stuck getting the grid to look right. Currently, I have a window that opens and the outside descriptor labels fill into the right places, but I can't figure out how to get my details about the item selected in the optionmenu to line up nicely in it's row. Everything that would be based off the optionmenu selection appears at the bottom of the window and doesn't change after the first selection. What can I do to fix this?
import tkinter as tk
from tkinter import *
window = tk.Tk()
frm_form = tk.Frame()
frm_form.pack()
labels = ["Name", "QualA", "QualB", "QualC", "QualD"]
for idx, text in enumerate(labels):
label = tk.Label(master=frm_form, text=text)
label.grid(row=0, column=idx + 1, sticky="w")
for i in range(1, 4):
label = tk.Label(master=frm_form, text=i)
label.grid(row=i, column=0, stick="e")
names = ["Bob", "Paul", "Steve", ]
Bob = ["Bob", "qual1", "qual2", "qual3", "qual4", ]
Paul = ["Paul", "qual5", "qual6", "qual7", "qual8", ]
Steve = ["Steve", "qual9", "qual10", "qual11", "qual12", ]
for i in range(1, 4):
def selected(event):
for j in range(2, 6):
if clicked.get() == 'Bob':
person = tk.Label(frm_form, text=Bob[j-1])
person.grid(row=i, column=j)
elif clicked.get() == 'Paul':
person = tk.Label(frm_form, text=Paul[j-1])
person.grid(row=i, column=j)
elif clicked.get() == 'Steve':
person = tk.Label(frm_form, text=Steve[j-1])
person.grid(row=i, column=j)
clicked = StringVar()
clicked.set(names[0])
drop = tk.OptionMenu(frm_form, clicked, *names, command=selected)
drop.grid(row=i, column=1)
window.mainloop()
This is a personal project, my first forray into coding with python ever, and all based off some loose knowledge from a progamming class or two many years ago alongside some youtube videos recently. As such, if there is a more efficient way to do what I'm aiming to here I am very open to suggestions.