1

I have such python script based on Tkinter:

#!/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()

As you can see the button is disabled but function 'pre' works whan i pushes disabled button.The visual it disabled but...Anyone, can help me?

2 Answers 2

1

The DISABLED field of the button only controls the built-in callback for the button. If you make a separate "handmade" binding on your own, the state of the button will not affect that.

Here's how to make the disabling functionality work as you expect:

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)
Sign up to request clarification or add additional context in comments.

Comments

1

You have disabled your button but it does not unbind the the function. You need to unbind the function which is associate to the button.

You need to add button3.unbind('<Button-1>') this line.

You can update your code like this :

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) 
button3.unbind('<Button-1>') #updated line
root.mainloop()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.