简体   繁体   中英

Python TkInter - Multiple Comboboxes copying eachother's selected value

I am writing a simple GUI with Tkinter in Python. I need two different comboboxes. However, when I select a value on the first combobox, for some reason it writes that value onto the second, and viceversa, as if they were linked. How can I unlink them? Here is my code.

subjects = Combobox(frame_answer,text = ("Arial",20), width = 60,height =40) 
subjects.grid(row = 20, column = 50)
questions = Combobox(frame_answer,text = ("Arial",20), width = 60,height = 40)
questions.grid(row = 40, column = 50)
questions["values"] = ["Select","Question1","Queston2","Question3"]
subjects["values"] = ["Select","Math","Science","Spanish"]

You passed text parameter to both combobox. I believe what you meant is font instead.

subjects = ttk.Combobox(root,font = ("Arial",20), width = 60,height =40)
questions = ttk.Combobox(root,font = ("Arial",20), width = 60,height = 40)

By using text you actually created a common textvariable for both combobox. You can check by calling subjects.config() and questions.config() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM