Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8401485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:49:08+00:00 2026-06-09T21:49:08+00:00

I have a python-tkinter gui app that I’ve been trying to find some way

  • 0

I have a python-tkinter gui app that I’ve been trying to find some way to add in some functionality. I was hoping there would be a way to right-click on an item in the app’s listbox area and bring up a context menu. Is tkinter able to accomplish this? Would I be better off looking into gtk or some other gui-toolkit?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:49:09+00:00Added an answer on June 9, 2026 at 9:49 pm

    You would create a Menu instance and write a function that calls
    its post() or tk_popup() method.

    The tkinter documentation doesn’t currently have any information about tk_popup().
    Read the Tk documentation for a description, or the source:

    library/menu.tcl in the Tcl/Tk source:

    ::tk_popup --
    This procedure pops up a menu and sets things up for traversing
    the menu and its submenus.
    
    Arguments:
    menu  - Name of the menu to be popped up.
    x, y  - Root coordinates at which to pop up the menu.  
    entry - Index of a menu entry to center over (x,y).  
            If omitted or specified as {}, then menu's  
            upper-left corner goes at (x,y).  
    

    tkinter/__init__.py in the Python source:

    def tk_popup(self, x, y, entry=""):
        """Post the menu at position X,Y with entry ENTRY."""
        self.tk.call('tk_popup', self._w, x, y, entry)
    

    You associate your context menu invoking function with right-click via:
    the_widget_clicked_on.bind("<Button-3>", your_function).

    However, the number associated with right-click is not the same on every platform.

    library/tk.tcl in the Tcl/Tk source:

    On Darwin/Aqua, buttons from left to right are 1,3,2.  
    On Darwin/X11 with recent XQuartz as the X server, they are 1,2,3; 
    other X servers may differ.
    

    Here is an example I wrote that adds a context menu to a Listbox:

    import tkinter # Tkinter -> tkinter in Python 3
    
    class FancyListbox(tkinter.Listbox):
    
        def __init__(self, parent, *args, **kwargs):
            tkinter.Listbox.__init__(self, parent, *args, **kwargs)
    
            self.popup_menu = tkinter.Menu(self, tearoff=0)
            self.popup_menu.add_command(label="Delete",
                                        command=self.delete_selected)
            self.popup_menu.add_command(label="Select All",
                                        command=self.select_all)
    
            self.bind("<Button-3>", self.popup) # Button-2 on Aqua
    
        def popup(self, event):
            try:
                self.popup_menu.tk_popup(event.x_root, event.y_root, 0)
            finally:
                self.popup_menu.grab_release()
    
        def delete_selected(self):
            for i in self.curselection()[::-1]:
                self.delete(i)
    
        def select_all(self):
            self.selection_set(0, 'end')
    
    
    root = tkinter.Tk()
    flb = FancyListbox(root, selectmode='multiple')
    for n in range(10):
        flb.insert('end', n)
    flb.pack()
    root.mainloop()
    

    The use of grab_release() was observed in an example on effbot.
    Its effect might not be the same on all systems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python GUI that uses Tkinter. I have to SSH into another
I have an app I'm trying to translate which uses tkinter and python, but
I have a simple Tkinter app in Python. I'd like to add help document
I have Python nested list that I'm trying to organize and eventually count number
I have a python based tkinter script which executes some commands using subprocess module.
I'm trying to create a Tkinter GUI that saves all entry box values into
I'm trying create a gui using Tkinter that grabs a username and password and
I'm trying to make a simple GUI calculator in Python with Tkinter. However the
I've been tinkering around with Python lately and wanted to make a GUI that
I have a Python Tkinter GUI which solicits file names from the user. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.