python - Tkinter(python) 禁用按钮调用方法

标签 python button tkinter

我有这样的基于 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/

相关文章:

python - 如何使用python脚本提取单引号内的字符串

android - 按下状态时如何移动按钮文本

python - 使用 python arduino 移动 Helm 机

python - 使用 Tkinter 命令 "iconbitmap"设置窗口图标

Python程序输出数字后跟 'L'

python - 使用 Tensorflow 2 的 Keras 功能 API 时传递 `training=true`

python - Pandas 爆炸列只有非零值

java - 将按钮添加到 GXT 网格单元

android - 带有添加照片按钮的 Gridview

python - 为什么我不能在函数内定义(和保存)Tkinter 字体?