I am trying to create a drop down selection for a personal program, that auto updates the name being shown based on the selected item.
The thing is, regardless of what is selected or what the default value should be, it always auto changes the selected name to the last option the user can choose and it will not change if another option is selected.
import tkinter
from tkinter import *
def changename(name=str):
selectedText.set(name)
mb.grid(row=1,column=1)
def startmainloop(var):
var.mainloop()
root = Tk()
label0=Label(root,text=".....")
label0.grid(row=0,columnspan=2)
selectedText=StringVar()
selectedText.set("Select Race")
mb=Menubutton(root, textvariable=selectedText,relief=GROOVE)
label1=Label(root, text="RACE")
label1.grid(row=1,column=0)
mb.grid()
mb.menu=Menu(mb, tearoff=0)
mb.menu.add_command(label="Argonian", command=changename("Argonian"))
mb.menu.add_command(label="Khajiit", command=changename("Khajiit"))
mb["menu"]=mb.menu
startmainloop(root)
In the image that would be above, the default that it should be showing is "Select Race". A drop down menu appears after clicking on Select Race with the two command options "Argonian" and "Khajiit". After clicking on the option "Argonian", the "Select Race" label of the menu should change to "Argonian". The option "Khajiit" though seems to be overloading the default and won't change regardless of the user selecting Argonian.
Nonetype?command=changename("Argonian")when you select that menu option, because it'll try to callNone, which doesn't work.