Right click on Mac with Tkinter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sudiptachatterjee
    New Member
    • Apr 2007
    • 3

    #1

    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?
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by sudiptachatterj ee
    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.s tate
    Code:
    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

    Comment

    • sudiptachatterjee
      New Member
      • Apr 2007
      • 3

      #3
      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
      Code:
      from Tkinter import *
      if __name__ == "__main__":
          root = Tk()
      
          def OnButton(event):
              print event.state
      
          button = Button(root, text='test')
          button.bind("[B]<Button-3>[/B]", 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

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by sudiptachatterj ee
        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
        Code:
        from Tkinter import *
        if __name__ == "__main__":
            root = Tk()
        
            def OnButton(event):
                print event.state
        
            button = Button(root, text='test')
            button.bind("[B]<Button-3>[/B]", 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).

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Is it possible (have you tried) that a one-button mouse generates <Button-2> events?

          Comment

          Working...