python - Tkinter .bind 无法绑定使用函数创建的按钮
问题描述
基本上,我想使用函数创建一个具有 .bind() 的按钮
def button():
btn = Button(main, text="HI").pack()
btn.bind("<button-1>", lambda x="hi":print(x))
main = Tk()
button()
main.mainloop()
但是它没有工作,而是返回
Traceback (most recent call last):
File "d:\source\Learn_management\test.py", line 9, in <module>
button()
File "d:\source\Learn_management\test.py", line 6, in button
btn.bind("<Shift_L>", lambda x="hi":print(x))
AttributeError: 'NoneType' object has no attribute 'bind'
有没有快速解决这个问题的方法?感谢阅读
解决方案
推荐阅读
- c++ - 链接到旧库:-lgfortranbegin 从预制的 makefile
- oracle - 如何在包中创建 PL/SQL 函数
- rest - 如何使用 HATEOAS 设置相关对象?
- swift - 从 Firebase 检索无价值的数据
- json.net - 如何解析“uuuu'-'MM'-'dd'T'HH':'mm':'ss;FFFFFFFFFo
“变成瞬间? - java - 来自不同函数的线程中断
- eclipse - 防止日食跳过自动添加的右括号
- java - 使用 Coherence jar 运行多播测试时出错
- ios - 当所有文本字段都填写在tableviewcell(SWIFT)中时如何启用按钮
- grails - GGTS 下载页面的 404