Hi everyone,
I am building a GUI app using python and Tkinter. I used bind() to attach the right-click event on <Button-3> for executing some commands (to popup a menu, specifically) --- and it is working fine on the PC. However, on a Mac laptop or machine, it just doesn't work (using Ctrl-Click, that is).
I found this old thread in the archives too: http://www.thescripts.com/forum/thread493721.html but there aren't any answers. Can someone please help me out?
4 7096
Hi everyone,
I am building a GUI app using python and Tkinter. I used bind() to attach the right-click event on <Button-3> for executing some commands (to popup a menu, specifically) --- and it is working fine on the PC. However, on a Mac laptop or machine, it just doesn't work (using Ctrl-Click, that is).
I found this old thread in the archives too: http://www.thescripts.com/forum/thread493721.html but there aren't any answers. Can someone please help me out?
I'm no Mac user, but you can get a bitmap of the keys that are down from the Tkinter.Event.state - from Tkinter import *
-
if __name__ == "__main__":
-
root = Tk()
-
-
def OnButton(event):
-
print event.state
-
-
button = Button(root, text='test')
-
button.bind("<Button-1>", OnButton)
-
button.pack()
-
-
-
root.mainloop()
-
# No Keys pressed
-
##8
-
# Sift down
-
##9
-
# Ctrl down
-
##12
-
Thanks a lot for the reply. But I am not being able to bind to the right-click in the first place. In your example, when I use -
from Tkinter import *
-
if __name__ == "__main__":
-
root = Tk()
-
-
def OnButton(event):
-
print event.state
-
-
button = Button(root, text='test')
-
button.bind("<Button-3>", OnButton)
-
button.pack()
-
-
-
root.mainloop()
-
I keep getting a '0' at the shell prompt, which I was getting with a binding to button 1 as well on the PC. On a MAC, however, the right-click just simply doesn't work.
Thanks a lot for replying --- I'll hunt around and post a solution here if I find one
Thanks a lot for the reply. But I am not being able to bind to the right-click in the first place. In your example, when I use -
from Tkinter import *
-
if __name__ == "__main__":
-
root = Tk()
-
-
def OnButton(event):
-
print event.state
-
-
button = Button(root, text='test')
-
button.bind("<Button-3>", OnButton)
-
button.pack()
-
-
-
root.mainloop()
-
I keep getting a '0' at the shell prompt, which I was getting with a binding to button 1 as well on the PC. On a MAC, however, the right-click just simply doesn't work.
Thanks a lot for replying --- I'll hunt around and post a solution here if I find one
Bind to the left-click and get the state of the event to see if the ctrl key is down, then process as if it were a right click (unless the Event class is defined diferently on the Mac).
Is it possible (have you tried) that a one-button mouse generates <Button-2> events?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Josh |
last post by:
Caution, newbie approaching...
I'm trying to come up with a very simple Tkinter test application that
consists of a window with a drop-down menu bar at the top and a grid
of colored rectangles...
|
by: srijit |
last post by:
Hello,
Any idea - why the following code crashes on my Win 98 machine with
Python 2.3? Everytime I run this code, I have to reboot my machine.
I also have Win32all-157 installed.
from Tkinter...
|
by: Ringwraith |
last post by:
Hello!
How to detect in Python that some click action was performed in some module
imported by my main module?
Let's assume I have a tree.py module that implements all functionality of a
tree...
|
by: SeeBelow |
last post by:
Do many people think that wxPython should replace Tkinter? Is this
likely to happen?
I ask because I have just started learning Tkinter, and I wonder if I
should abandon it in favor of...
|
by: Tuvas |
last post by:
I am trying to execute a function with a tkinter event binding double
click. With 2 mouse clicks done quickly, the function should happen,
otherwise, it should not. However, I am noticing that the...
|
by: dwelch91 |
last post by:
I'm trying unsuccessfully to do something in Tk that I though would be
easy. After Googling this all day, I think I need some help. I am
admittedly very novice with Tk (I started with it...
|
by: Ben Kovitz |
last post by:
Hi, I just tried to run Tkinter on OS X 10.3.9 under Python 2.4.3, and
I'm getting a bus error as soon as I call Tk(). Googling has turned up
info other Tkinter bus errors, but not this one that...
|
by: karthikbalaguru |
last post by:
Hi,
One of my python program needs tkinter to be installed to run
successfully.
I am using Redhat 9.0 and hence tried installing by copying the
tkinter-2.2.2-36.i386.rpm
alone from the CD 3 to...
|
by: joshdw4 |
last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes,
it's that pesky root window and I have tried withdraw to no avail. I'm
assuming this is because of the methods I'm using. I...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |