472,146 Members | 1,358 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

tkinter btn visual state with tkMessageBox

why is the button sunken when called through a bind method, and not
with the command attribute?
Thank you!
## Cut'nPaste example
from Tkinter import *
import tkMessageBox

class Vue(object):
def __init__(self):
self.root=Tk()
self.root.title("test button visual state")
self.b1=Button(self.root,text="tkMessageBox.showin fo with bind
:-(") #,command=self.showMsg)
self.b1.bind("<Button>",self.showMsg)
self.b2=Button(self.root,text="tkMessageBox.showin fo with
command :-)",command=self.showMsg)
self.b1.pack()
self.b2.pack()
self.root.mainloop()
def showMsg(self,evt=1):
if evt==1:
txt="From button with command"
else:
txt="From button with bind"
tkMessageBox.showinfo("Test of button", txt)

if __name__=="__main__":
v=Vue()

Aug 19 '06 #1
4 3095

<jm*********@gmail.comwrote:

To: <py*********@python.org>
| why is the button sunken when called through a bind method, and not
| with the command attribute?
| Thank you!
|
|
| ## Cut'nPaste example
| from Tkinter import *
| import tkMessageBox
|
| class Vue(object):
| def __init__(self):
| self.root=Tk()
| self.root.title("test button visual state")
| self.b1=Button(self.root,text="tkMessageBox.showin fo with bind
| :-(") #,command=self.showMsg)
| self.b1.bind("<Button>",self.showMsg)

8<---------------------------------------------------------------------------

change this to :

self.b1.bind("<ButtonRelease>",self.showMsg)

Problem is that a button "sinks in" when you press it and "springs back" when
you release it...

and the "Button" leaves it sunken.... - because when you release, the control is
no longer there

- Hendrik


Aug 19 '06 #2

Hendrik van Rooyen wrote:
<jm*********@gmail.comwrote:

To: <py*********@python.org>
| why is the button sunken when called through a bind method, and not
| with the command attribute?
| Thank you!
|
|
| ## Cut'nPaste example
| from Tkinter import *
| import tkMessageBox
|
| class Vue(object):
| def __init__(self):
| self.root=Tk()
| self.root.title("test button visual state")
| self.b1=Button(self.root,text="tkMessageBox.showin fo with bind
| :-(") #,command=self.showMsg)
| self.b1.bind("<Button>",self.showMsg)

8<---------------------------------------------------------------------------

change this to :

self.b1.bind("<ButtonRelease>",self.showMsg)

Problem is that a button "sinks in" when you press it and "springs back" when
you release it...

and the "Button" leaves it sunken.... - because when you release, the control is
no longer there

- Hendrik
Thanks Hendrik - is the command attribute connected to the bindable
events?
jm

Aug 19 '06 #3
<jm*********@gmail.comWrote:
|
| Hendrik van Rooyen wrote:
| <jm*********@gmail.comwrote:
| >
| To: <py*********@python.org>
| >
| >
| | why is the button sunken when called through a bind method, and not
| | with the command attribute?
| | Thank you!
| |
| |
| | ## Cut'nPaste example
| | from Tkinter import *
| | import tkMessageBox
| |
| | class Vue(object):
| | def __init__(self):
| | self.root=Tk()
| | self.root.title("test button visual state")
| | self.b1=Button(self.root,text="tkMessageBox.showin fo with bind
| | :-(") #,command=self.showMsg)
| | self.b1.bind("<Button>",self.showMsg)
| >
| >
8<---------------------------------------------------------------------------
| >
| change this to :
| >
| self.b1.bind("<ButtonRelease>",self.showMsg)
| >
| Problem is that a button "sinks in" when you press it and "springs back"
when
| you release it...
| >
| and the "Button" leaves it sunken.... - because when you release, the
control is
| no longer there
| >
| - Hendrik
| Thanks Hendrik - is the command attribute connected to the bindable
| events?
| jm

I don't have a clue - you are either asking about advanced magic here,
or I don't understand your question - I believe the lower level routines
are common, but I don't *Know* this - so its a pity that some people
who shall be nameless have beaten their brains out in a thread about
a directory name here..

You may have noticed that there is another subtle bug with what I have
suggested to you - when you press the offending button, then move the
mouse to move the cursor off the screen button, - the button
"springs back" as expected - but then when you release the mouse
button, off the screen button, the call back is done anyway, instead of
being cancelled when the cursor moves off the screen button.

- for the command case, the sequence is different, and the call back is done
only if the release is done on the screen button...

- But this may just be my setup - does yours do the same?

I don't know how to fix that - you could look at sequences of events - button
push followed by release - But I doubt whether this will help, as its doing
something like that anyway (haven't tried it)

- Hendrik


Aug 20 '06 #4

Hendrik van Rooyen wrote:
<jm*********@gmail.comWrote:
|
| Hendrik van Rooyen wrote:
| <jm*********@gmail.comwrote:
| >
| To: <py*********@python.org>
| >
| >
| | why is the button sunken when called through a bind method, and not
| | with the command attribute?
| | Thank you!
| |
| |
| | ## Cut'nPaste example
| | from Tkinter import *
...
| and the "Button" leaves it sunken.... - because when you release, the
control is
| no longer there
| >
| - Hendrik
| Thanks Hendrik - is the command attribute connected to the bindable
| events?
| jm

I don't have a clue - you are either asking about advanced magic here,
or I don't understand your question - I believe the lower level routines
are common, but I don't *Know* this - so its a pity that some people
who shall be nameless have beaten their brains out in a thread about
a directory name here..

You may have noticed that there is another subtle bug with what I have
suggested to you - when you press the offending button, then move the
mouse to move the cursor off the screen button, - the button
"springs back" as expected - but then when you release the mouse
button, off the screen button, the call back is done anyway, instead of
being cancelled when the cursor moves off the screen button.

- for the command case, the sequence is different, and the call back is done
only if the release is done on the screen button...

- But this may just be my setup - does yours do the same?

I don't know how to fix that - you could look at sequences of events - button
push followed by release - But I doubt whether this will help, as its doing
something like that anyway (haven't tried it)

- Hendrik
Same behavior here - Also, I added a bind to Button event and another
to ButtonRelease, and also had the command attribute. All three
*events* are processed, in similar fashion that you describe above.
Finally, the command attribute seems to works like a ButtonRelease BUT
still permits a binding to another function on a ButtonRelease event
(and only one) so if the lower level functions might be the same the
path to them seem different.
I found this article that pertains to the question:
http://www.ferg.org/thinking_in_tkinter/tt075.py
but I'll postpone my own investigation at this time to return to my
program ;-)
Thanks again,

Jean-Marc

Aug 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ajay | last post: by
1 post views Thread by Club-B42 | last post: by
6 posts views Thread by Peter Kleiweg | last post: by
3 posts views Thread by Glen | last post: by
reply views Thread by Stewart Midwinter | last post: by
4 posts views Thread by Gigs_ | last post: by
8 posts views Thread by rahulnag22 | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.