[问题] tkinter下两个拉式选单连动的问题

楼主: Dmix   2019-03-28 08:58:53
请问各位:
我有两个下单式选单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里呢?
作者: tommyptt (Alga)   2019-03-28 21:31:00
没用过combobox ,但tkinter物件里的选项通常在建立的时候就决定了,像optionmenu就是如此替代方案可以在def B里面再建立一个一样的物件并新增选项,来盖过旧的,可以达到一样的目的,但感觉有点治标不治本就是了

Links booklink

Contact Us: admin [ a t ] ucptt.com