我有这样的基于 Tkinter 的 python 脚本:
#!/usr/bin/env python
#-*-coding:utf-8-*-
import ttk
from Tkinter import *
root = ttk.Tkinter.Tk()
root.geometry("%dx%d+0+0" % (1280, 800))
root.title(u'СКЗ Аналитик')
def pre(event):
print 'Something'
button3=Button(root,state = DISABLED,text='Test',width=10,height=1,fg='black',font='arial 8')
button3.place(x = 1200, y = 365)
button3.bind('<Button-1>', pre)
root.mainloop()
正如您所看到的,按钮被禁用,但当我按下禁用按钮时,“pre”功能起作用。它禁用了视觉效果,但是......有人可以帮助我吗?
最佳答案
按钮的 DISABLED
字段仅控制按钮的内置回调。如果您自己制作单独的“手工”绑定(bind),则按钮的状态不会影响它。
以下是如何使禁用功能按您的预期工作:
button3=Button(root, command = pre, state = DISABLED,text='Test',width=10,height=1,fg='black',font='arial 8')
# ^^^^^^^^^^^^^ use the built-in command field for the button.
button3.place(x = 1200, y = 365)
关于python - Tkinter(python) 禁用按钮调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24016238/