tkinter的Checkbutton为什么没有variable、onvalue等成员变量

Susurrant 2015-09-28 11:48:55
我的python版本:3.4

根据网上教程、帖子:
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?
...全文
467 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
panghuhu250 2015-10-02
  • 打赏
  • 举报
回复
这儿讲的很清楚:http://effbot.org/tkinterbook/checkbutton.htm
Susurrant 2015-10-01
  • 打赏
  • 举报
回复
难道论坛里没人用tkinter吗。。。

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧