I would like to be able to create a dropdown list, and assign each choice in the list a different variable. When the option is selected from the dropdown, I would like an entry box to display the associated variable, not the name of the option.
In my program a dropdown list contains a list of people. Each person is a different age. How do I select the person using the dropdown and then have their age display in the entry box?
As you can see below I have entered the choices in this format name*age. I was hoping to try and split by the * and then select the age. I tried specifying the text of the entry box using: text = ((var.get()).split('*')[1]) but this did not work.
Please let me know if there is a way to achieve this.
from Tkinter import *
import Tkinter as ttk
from ttk import *
root = Tk()
root.title("Age Selector")
mainframe = Frame(root)
mainframe.grid(column=0,row=0, sticky=(N,W,E,S) )
mainframe.columnconfigure(0, weight = 1)
mainframe.rowconfigure(0, weight = 1)
mainframe.pack(pady = 10, padx = 10)
var = StringVar(root)
var.set('Bob')
choices = ['Bob*35', 'Garry*45', 'John*32', 'Hank*65','Tyrone*21']
option = OptionMenu(mainframe, var, *choices)
option.grid(row = 1, column =1)
Label(mainframe, text="Age").grid(row = 2, column = 1)
age = StringVar()
age_ent = Entry(mainframe, text = var, width = 15).grid(column = 2, row = 2)
root.mainloop()