Home > Software design >  Can I have mixed data types in a tkinter Combobox?
Can I have mixed data types in a tkinter Combobox?

Time:02-12

I'm trying to create a tkinter combobox with integers and strings as values. But it seems like whatever is selected from the combobox can only be assigned to either IntVar() or StringVar(). Is there a tkinter variable type that can take both integers and strings?

root = Tk()
root.geometry('{}x{}'.format(1000,1000))
integer = IntVar()
string = StringVar()
dropDownList = Combobox(root, value=[1,2,3,'x','y'], textvariable = integer) #what do I need to do with the textvariable?
dropDownList.pack()
root.mainloop()

CodePudding user response:

Is there a tkinter variable type that can take both integers and strings?

No, there is not. However, the value from a StringVar can easily be converted to an integer if it's in the proper format.

  • Related