作者Dmix ()
看板Python
标题[问题] tkinter下两个拉式选单连动的问题
时间Thu Mar 28 08:58:53 2019
请问各位:
我有两个下单式选单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://webptt.com/cn.aspx?n=bbs/Python/M.1553734736.A.0C0.html
1F:推 tommyptt: 没用过combobox ,但tkinter物件里的选项通常在建立的 03/28 21:31
2F:→ tommyptt: 时候就决定了,像optionmenu就是如此 03/28 21:31
3F:推 tommyptt: 替代方案可以在def B里面再建立一个一样的物件并新增选 03/28 21:36
4F:→ tommyptt: 项,来盖过旧的,可以达到一样的目的,但感觉有点治标 03/28 21:36
5F:→ tommyptt: 不治本就是了 03/28 21:36