tkinter btn visual state with tkMessageBox

J

jmdeschamps

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.showinfo with bind
:-(") #,command=self.showMsg)
self.b1.bind("<Button>",self.showMsg)
self.b2=Button(self.root,text="tkMessageBox.showinfo 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()
 
H

Hendrik van Rooyen

To: <[email protected]>


| 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.showinfo 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
 
J

jmdeschamps

Hendrik said:
To: <[email protected]>


| 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.showinfo 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
 
H

Hendrik van Rooyen

|
| Hendrik van Rooyen wrote:
| >
| > To: <[email protected]>
| >
| >
| > | 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.showinfo 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
 
J

jmdeschamps

Hendrik said:
|
| Hendrik van Rooyen wrote:
| >
| > To: <[email protected]>
| >
| >
| > | 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top