看板 Python 關於我們 聯絡資訊
請問各位: 我有兩個下單式選單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
tommyptt: 沒用過combobox ,但tkinter物件裡的選項通常在建立的 03/28 21:31
tommyptt: 時候就決定了,像optionmenu就是如此 03/28 21:31
tommyptt: 替代方案可以在def B裡面再建立一個一樣的物件並新增選 03/28 21:36
tommyptt: 項,來蓋過舊的,可以達到一樣的目的,但感覺有點治標 03/28 21:36
tommyptt: 不治本就是了 03/28 21:36