tk.Radiobutton值(v.get())是正确的,但是当我尝试在函数外部评估ShowChoice时,该值保持在初始值。我在使用'return'吗 错误地?
import Tkinter as tk
root = tk.Tk()
v = tk.IntVar()
v.set(0) # initializing the choice, i.e. python
def ShowChoice():
x = v.get() # these values are correct
print x
return x
radio1 = tk.Radiobutton(root, text='python', padx = 20,variable=v, command=ShowChoice, value=0)
radio1.pack(anchor=tk.W)
radio2 = tk.Radiobutton(root, text='java', padx = 20, variable=v,command=ShowChoice, value=1)
radio2.pack(anchor=tk.W)
q = ShowChoice() # this does not show the
print q # the value for the last
root.mainloop() # button pushed