Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter dropdown Menu with keyboard shortcuts?

Tags:

I would like to have a Dropdown Menu in Tkinter, that includes the shortcut key associated with this command. Is this possible?

How would I also add the underline under a certain character, to allow for Alt-F-S (File->Save)?

like image 962
skeggse Avatar asked Aug 14 '10 22:08

skeggse


People also ask

How will you activate a menu using a keyboard?

Many keyboards have a Windows key which will bring up the start menu. The keyboard combination Ctrl+Esc also brings up this menu. The up and down arrow keys allow you to move through the menu items. Those items with a submenu are visually indicated with a small black triangle/arrowhead.

How do you drop down in tkinter?

Let us suppose we want to create a dropdown menu of a list in an application using tkinter. In this case, we can use the Tkinter OptionMenu(win, menu_to_set, options) function. First, we will instantiate an object of StringVar(), then we will set the initial value of the dropdown menu.

Which syntax is used to create a drop down menu in python?

OptionMenu in Python Tkinter is used to create a drop-down menu in the application. It consumes less space and displays multiple options to the user. Users can select only one item out of the list of items.


1 Answers

import tkinter as tk import sys  class App(tk.Tk):      def __init__(self):         tk.Tk.__init__(self)         menubar = tk.Menu(self)         fileMenu = tk.Menu(menubar, tearoff=False)         menubar.add_cascade(label="File", underline=0, menu=fileMenu)         fileMenu.add_command(label="Exit", underline=1,                              command=quit, accelerator="Ctrl+Q")         self.config(menu=menubar)          self.bind_all("<Control-q>", self.quit)      def quit(self, event):         print("quitting...")         sys.exit(0)  if __name__ == "__main__":     app = App()     app.mainloop() 
like image 85
Bryan Oakley Avatar answered Sep 28 '22 21:09

Bryan Oakley