473,387 Members | 1,440 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,387 software developers and data experts.

Right click on Mac with Tkinter

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?
Apr 13 '07 #1
4 7096
bartonc
6,596 Expert 4TB
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
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. if __name__ == "__main__":
  3.     root = Tk()
  4.  
  5.     def OnButton(event):
  6.         print event.state
  7.  
  8.     button = Button(root, text='test')
  9.     button.bind("<Button-1>", OnButton)
  10.     button.pack()
  11.  
  12.  
  13.     root.mainloop()
  14. # No Keys pressed
  15. ##8
  16. # Sift down
  17. ##9
  18. # Ctrl down
  19. ##12
  20.  
Apr 13 '07 #2
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
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. if __name__ == "__main__":
  3.     root = Tk()
  4.  
  5.     def OnButton(event):
  6.         print event.state
  7.  
  8.     button = Button(root, text='test')
  9.     button.bind("<Button-3>", OnButton)
  10.     button.pack()
  11.  
  12.  
  13.     root.mainloop()
  14.  
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
Apr 16 '07 #3
bartonc
6,596 Expert 4TB
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
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. if __name__ == "__main__":
  3.     root = Tk()
  4.  
  5.     def OnButton(event):
  6.         print event.state
  7.  
  8.     button = Button(root, text='test')
  9.     button.bind("<Button-3>", OnButton)
  10.     button.pack()
  11.  
  12.  
  13.     root.mainloop()
  14.  
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).
Apr 16 '07 #4
bartonc
6,596 Expert 4TB
Is it possible (have you tried) that a one-button mouse generates <Button-2> events?
Apr 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
3
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...
2
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...
7
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...
1
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...
3
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...
5
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...
8
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...
3
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...
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: 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$) { } ...
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?
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
Oralloy
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,...
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...

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.