[問題] tkinter下兩個拉式選單連動的問題

看板Python作者時間6年前 (2019/03/28 08:58), 編輯推噓2(203)
留言5則, 1人參與, 6年前最新討論串1/1
請問各位: 我有兩個下單式選單A, B,當選單A選擇後會丟出一個值a,我希望選單B能收到a這個值, 請問該怎麼作? 下面是我的程式,請問我該修改哪裡呢? import tkinter as tk import pandas as pd import tkinter.ttk as tt gui = tk.Tk() gui.title('test') gui.geometry('800x450') def A(*args): a = A_grade.get() return a A_grade = tt.Combobox(gui, width = 50, values = ['1','2','3', '4'], justify = 'center') A_grade.place(x = 80, y = 355, width = 45, height = 20) A_grade.current(0) A_grade.bind("<<ComboboxSelected>>", A) a = A() def B(*args): b= B_grade.get() print(a) print(b) B_grade = tt.Combobox(gui, width = 50, values = ['5','7'], justify = 'center') B_grade.place(x = 80, y = 405, width = 45, height = 20) B_grade.current() B_grade.bind("<<ComboboxSelected>>", B) gui.mainloop() 執行選單B無法印出a的值,該怎麼把 a 丟到選單B裡呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.32.239.148 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1553734736.A.0C0.html

03/28 21:31, 6年前 , 1F
沒用過combobox ,但tkinter物件裡的選項通常在建立的
03/28 21:31, 1F

03/28 21:31, 6年前 , 2F
時候就決定了,像optionmenu就是如此
03/28 21:31, 2F

03/28 21:36, 6年前 , 3F
替代方案可以在def B裡面再建立一個一樣的物件並新增選
03/28 21:36, 3F

03/28 21:36, 6年前 , 4F
項,來蓋過舊的,可以達到一樣的目的,但感覺有點治標
03/28 21:36, 4F

03/28 21:36, 6年前 , 5F
不治本就是了
03/28 21:36, 5F
文章代碼(AID): #1Sd1nG30 (Python)
文章代碼(AID): #1Sd1nG30 (Python)