我的GUI中有两个单选按钮,当我按下“q'”时,我想打印我的选择。或者' w'。 (快捷方式)
import tkinter as tk
def print_selection(*event):
l.config(text='you have selected ' + var.get())
win = tk.Tk()
win.geometry("200x200")
var = tk.StringVar()
l = tk.Label(win, width=20, text='empty')
l.pack()
var.set('...')
r1 = tk.Radiobutton(win, text='A', variable=var, value='A', command=print_selection)
r1.pack()
r2 = tk.Radiobutton(win, text='B', variable=var, value='B', command=print_selection)
r2.pack()
r1.bind_all('<q>', print_selection) # press 'q' to show message
r2.bind_all('<w>', print_selection) # press 'w' to show message
win.mainloop()
标签l 显示您已选择... 当我按下&#39; q&#39;或者&#39; w但我希望标签l 显示您选择了A 或您选择了B 。如何解决它。