473,410 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

tkinter button state = DISABLED

I have created a button widget with a button click binding. The button
initially has a state=disabled. I can see the greyed out version of
the button in the GUI. But If I click on the button it still invokes
the callback/binding function.

Any suggestions as to why the callback is being invoked even though
the button has a disabled state. It looks like-

b=Button(frame, text = "Button", state = 'disabled')

b.bind("<ButtonRelease-1>",
lambda
event :
function()
)

Thanks
Rahul

May 14 '07 #1
8 11187
ra********@yahoo.com wrote:
I have created a button widget with a button click binding. The button
initially has a state=disabled. I can see the greyed out version of
the button in the GUI. But If I click on the button it still invokes
the callback/binding function.

Any suggestions as to why the callback is being invoked even though
the button has a disabled state. It looks like-

b=Button(frame, text = "Button", state = 'disabled')

b.bind("<ButtonRelease-1>",
lambda
event :
function()
)
Well, the /mouse/ button /was/ released. Do you know about the alternative?

b = Button(..., command=function) # no bind(), no lambda

It behaves like you expect.

Peter

May 14 '07 #2
On May 14, 12:01 pm, Peter Otten <__pete...@web.dewrote:
rahulna...@yahoo.com wrote:
I have created a button widget with a button click binding. The button
initially has a state=disabled. I can see the greyed out version of
the button in the GUI. But If I click on the button it still invokes
the callback/binding function.
Any suggestions as to why the callback is being invoked even though
the button has a disabled state. It looks like-
b=Button(frame, text = "Button", state = 'disabled')
b.bind("<ButtonRelease-1>",
lambda
event :
function()
)

Well, the /mouse/ button /was/ released. Do you know about the alternative?

b = Button(..., command=function) # no bind(), no lambda

It behaves like you expect.

Peter

So, then is it right to say that for a widget like button widget on
occurance of a 'event' the function which is bound to this event is
invoked, even if the button widget has its 'state' option set to
'disabled'. I was assuming that if the button widget has state =
'disabled' then even on a button event the binding function wont be
invoked.
I will take a look at the alternative code you suggested above too.

Thanks
Rahul

May 14 '07 #3
En Mon, 14 May 2007 17:46:32 -0300, <ra********@yahoo.comescribió:
On May 14, 12:01 pm, Peter Otten <__pete...@web.dewrote:
>rahulna...@yahoo.com wrote:
b=Button(frame, text = "Button", state = 'disabled')
b.bind("<ButtonRelease-1>",
lambda
event :
function()
)

Well, the /mouse/ button /was/ released. Do you know about the
alternative?

b = Button(..., command=function) # no bind(), no lambda
It behaves like you expect.

So, then is it right to say that for a widget like button widget on
occurance of a 'event' the function which is bound to this event is
invoked, even if the button widget has its 'state' option set to
'disabled'. I was assuming that if the button widget has state =
'disabled' then even on a button event the binding function wont be
invoked.
I will take a look at the alternative code you suggested above too.
Maybe there is a confusion here. You code above means that, when the event
"The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET
b, your function will be called.
The "alternative code" suggested is the right way; the "command" is fired
when the mouse button is pressed inside the widget AND then released
inside the SAME widget (and the button is not disabled).

--
Gabriel Genellina

May 14 '07 #4
ra********@yahoo.com wrote:
I have created a button widget with a button click binding. The button
initially has a state=disabled. I can see the greyed out version of
the button in the GUI. But If I click on the button it still invokes
the callback/binding function.

Any suggestions as to why the callback is being invoked even though
the button has a disabled state. It looks like-

b=Button(frame, text = "Button", state = 'disabled')

b.bind("<ButtonRelease-1>",
lambda
event :
function()
)

Thanks
Rahul
DISABLED refers to the whether the function supplied in the "command"
parameter is called when the button is pressed, other bindings are
irrelevant, so you will need code to re-bind any events you have bound
when the button is "disabled". So its better to just use the "command"
parameter rather than binding mouse events.

An exception is Checkbutton, where you might want to bind
<ButtonRelease-1and then query the button's state (or the state of an
IntVar associated with it) to make a decision--if you want a GUI to
respond real-time to user events.

James
May 15 '07 #5
"Gabriel Genellina" <ga*******@yahoo.com.arwrote:
>Maybe there is a confusion here. You code above means that, when the event
"The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET
b, your function will be called.
I have never seen this working in Tkinter, unless the button was pressed on the
widget
in question - and worse, once you have clicked down on a ButtonRelease binding
you can move the mouse pointer anywhere you like, even out of the application
and when you release it, the bound function is called...

Its either a bug or a feature, I don't know.

- Hendrik

May 16 '07 #6
En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen
<ma**@microcorp.co.zaescribió:
"Gabriel Genellina" <ga*******@yahoo.com.arwrote:
>Maybe there is a confusion here. You code above means that, when the
event
"The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET
b, your function will be called.

I have never seen this working in Tkinter, unless the button was pressed
on the
widget
in question - and worse, once you have clicked down on a ButtonRelease
binding
you can move the mouse pointer anywhere you like, even out of the
application
and when you release it, the bound function is called...

Its either a bug or a feature, I don't know.
Uhmm... I'm not sure I understand you completely. I only said that the
"command" is fired only when the mouse button is pressed on the widget,
AND released inside the same widget. If both events don't happen in the
same widget, "command" won't fire. Maybe you are saying the same thing...
anyway I'm not a Tk expert.

--
Gabriel Genellina

May 16 '07 #7
"Gabriel Genellina" <ga*******@yahoo.com.arwrote:

>En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen
<ma**@microcorp.co.zaescribió:
> "Gabriel Genellina" <ga*******@yahoo.com.arwrote:
>>Maybe there is a confusion here. You code above means that, when the
event
"The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET
b, your function will be called.

I have never seen this working in Tkinter, unless the button was pressed
on the
widget
in question - and worse, once you have clicked down on a ButtonRelease
binding
you can move the mouse pointer anywhere you like, even out of the
application
and when you release it, the bound function is called...

Its either a bug or a feature, I don't know.

Uhmm... I'm not sure I understand you completely. I only said that the
"command" is fired only when the mouse button is pressed on the widget,
AND released inside the same widget. If both events don't happen in the
same widget, "command" won't fire. Maybe you are saying the same thing...
anyway I'm not a Tk expert.
No command is ok and you have described it right - its ButtonRelease that
seems broken to me

- Hendrik

May 17 '07 #8
On Thu, 17 May 2007 09:30:57 +0200, Hendrik van Rooyen
<ma**@microcorp.co.zawrote:
"Gabriel Genellina" <ga*******@yahoo.com.arwrote:
>En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen
>>I have never seen this working in Tkinter, unless the button was
pressed
on the
widget
in question - and worse, once you have clicked down on a ButtonRelease
binding
you can move the mouse pointer anywhere you like, even out of the
application
and when you release it, the bound function is called...

Its either a bug or a feature, I don't know.

Uhmm... I'm not sure I understand you completely. I only said that the
"command" is fired only when the mouse button is pressed on the widget,
AND released inside the same widget. If both events don't happen in the
same widget, "command" won't fire. Maybe you are saying the same
thing...
anyway I'm not a Tk expert.

No command is ok and you have described it right - its ButtonRelease that
seems broken to me
Apparently, this behaviour is the intended one, at least for buttons; see:
http://www.tcl.tk/man/tcl8.4/TkCmd/bind.htm#M11

As for the question "why?", maybe you should ask it on the c.l.tcl
newsgroup?
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
May 18 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: JyotiC | last post by:
hi, i am making a GUI using Tkinter, I have a button and a checkbutton. i want the button to be enable when checkbutton is on and disble when the checkbutton is off. thanx
1
kaarthikeyapreyan
by: kaarthikeyapreyan | last post by:
Beginners Game- Tic-Tac-Toe My first attempt after learning Tkinter from Tkinter import * import tkFont class myApp: """ Defining The Geometry of the GUI And the variables Used In the...
7
by: Peter Pearson | last post by:
Tkinter makes it very easy to drag jpeg images around on a canvas, but I would like to have a "target" change color when the cursor dragging an image passes over it. I seem to be blocked by the...
1
by: viv1tyagi | last post by:
Hi everyone ! ! ! I'm just a month old in the world of Python and trying to develop an application using Tkinter in which a new window pops out on a particular button press.The code for this new...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.