Reputation: 21
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?
Upvotes: 1
Views: 1240
Reputation: 5414
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()
Upvotes: 1
Reputation: 14118
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)
Upvotes: 1