473,381 Members | 1,450 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,381 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 3173

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ajay | last post by:
hi! my application consists of a GUI with a number of functions. One of these runs a server in a separate thread. the thread is started and given the function start_server to execute the...
1
by: Club-B42 | last post by:
when i start opt_newlogin.py directly it works fine(outputs '1 1 1 1'), but if i start it from options.py there is an error(outputs ''). ======== opt_newlogin.py ======== from config import *...
6
by: Peter Kleiweg | last post by:
I have an application written in Tkinter. There is a menu item 'quit' that calls the function 'quit'. If 'quit' is called, it first checks if there is unsaved data. If there is, it won't let the...
3
by: Glen | last post by:
Is it possible to to detect a Tkinter top-level window being closed with the close icon/button (top right), for example to call a function before the window actually closes? Python 2.4 / Linux...
0
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo...
4
by: Gigs_ | last post by:
class MenuDemo(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack(expand=YES, fill=BOTH) self.createWidgets() def createWidgets(self): self.makeMenuBar()...
8
by: rahulnag22 | last post by:
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...
0
by: Guilherme Polo | last post by:
On Thu, Aug 28, 2008 at 10:29 AM, <dudeja.rajat@gmail.comwrote: It is good to post a short code sample that demonstrates the problem, but it has to run by itself at least. tkMessageBox...
7
by: Haiyan | last post by:
Dear experts: I am trying to add one xy-scrollbar on the canvas, then put lots of check buttons on the canvas. I got at least following 2 problems: 1.I can see the y-scroll bar but contents on...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.