小弟最近初学python有一个问题有点困惑
我用Tkinter写了一个小视窗
from Tkinter import *
class radio_practice:
def __init__(self, master):
self.v = IntVar()
self.frame = Frame(master)
self.label = Label(master, text = 'choose a language',
justify = LEFT, font = ('times',26))
self.label.pack(fill = BOTH, side = TOP)
self.botton1 = Radiobutton(master, text = 'python',
variable = self.v, value = 1,
command = self.print_variable)
self.botton1.pack(fill = BOTH, side = LEFT, expand = True)
self.botton2 = Radiobutton(master, text = 'C#', v
ariable = self.v, value = 2,
command = self.print_variable)
self.botton2.pack(fill = BOTH, side = LEFT, expand = True)
def print_variable(self):
print self.v.get()
root = Tk()
program_choose = radio_practice(root)
root.mainloop()
后面那个print_variable function是为了观察一下self.v会不会被我按下button后改变
的状况,但是我的command如果 = self.print_variable()程式一跑self.v就会被印出来
而且任凭我怎么点按钮也不会显示出被改过的self.v,但是如果没有那个括号就可以如
预期看到self.v被改变
想请问在class里面呼叫function有没有括号的意义有何不同?
档案请由此下载:
https://www.dropbox.com/s/mgml6286tfmi5g8/radiobutton.py?dl=0