根据网上教程、帖子:
from tkinter import *
root = Tk()
def p():
print('checkbutton')
#如何打印调用此函数的checkbutton的text?
chk = Checkbutton(root, text = 'checkbutton', variable = 1, onvalue = 1, command = p)
chk.pack()
print(chk.variable)
print(chk.onvalue)
root.mainloop()
运行显示:
print(chk.variable)
AttributeError: 'Checkbutton' object has no attribute 'variable'
怎么回事?
另外,如果有多个checkbutton的command都为函数p, 这些checkbutton的text不一样,如何打印调用此函数的checkbutton的text?