Python tkinter.Menu() Examples
The following are 30
code examples of tkinter.Menu().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tkinter
, or try the search function
.
Example #1
Source File: friendslist.py From Tkinter-GUI-Programming-by-Example with MIT License | 7 votes |
def __init__(self, **kwargs): super().__init__(**kwargs) self.title('Tk Chat') self.geometry('700x500') self.menu = tk.Menu(self, bg="lightgrey", fg="black", tearoff=0) self.friends_menu = tk.Menu(self.menu, fg="black", bg="lightgrey", tearoff=0) self.friends_menu.add_command(label="Add Friend", command=self.show_add_friend_window) self.avatar_menu = tk.Menu(self.menu, fg="black", bg="lightgrey", tearoff=0) self.avatar_menu.add_command(label="Change Avatar", command=self.change_avatar) self.menu.add_cascade(label="Friends", menu=self.friends_menu) self.menu.add_cascade(label="Avatar", menu=self.avatar_menu) self.requester = Requester() self.show_login_screen()
Example #2
Source File: case.py From mentalist with MIT License | 6 votes |
def add_upper_button(self): mb = Tk.Menubutton(self.upper_frame, text=' + ', relief='raised', font=('Helvetica', '14')) mb.menu = Tk.Menu(mb, tearoff=0) mb['menu'] = mb.menu label = 'No Case Change' mb.menu.add_command(label=label, command=partial(self.controller.add_attr, label=label, node_view=self, attr_class=model.NothingMutatorAttr)) m_cases = [None, None] for i, case in enumerate(['Lowercase', 'Uppercase']): m_cases[i] = Tk.Menu(mb, tearoff=0) mb.menu.add_cascade(label='{}'.format(case), menu=m_cases[i], underline=0) for type_ in ['All', 'First']: if type_ == 'First': if case == 'Lowercase': suffix = ', Upper Rest' else: suffix = ', Lower Rest' else: suffix = '' label = '{} {}{}'.format(case, type_, suffix) m_cases[i].add_command(label=label, command=partial(self.controller.add_attr, label=label, node_view=self, attr_class=model.CaseAttr, type_=type_, case=case)) mb.menu.add_command(label='Toggle Nth...', command=partial(self.open_case_popup, 'Toggle')) mb.pack(side='left', fill='x', padx=10, pady=5)
Example #3
Source File: friendslist.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
def __init__(self, **kwargs): super().__init__(**kwargs) self.title('Tk Chat') self.geometry('700x500') self.menu = tk.Menu(self, bg="lightgrey", fg="black", tearoff=0) self.friends_menu = tk.Menu(self.menu, fg="black", bg="lightgrey", tearoff=0) self.friends_menu.add_command(label="Add Friend", command=self.add_friend) self.menu.add_cascade(label="Friends", menu=self.friends_menu) self.configure(menu=self.menu) self.canvas = tk.Canvas(self, bg="white") self.canvas_frame = tk.Frame(self.canvas) self.scrollbar = ttk.Scrollbar(self, orient="vertical", command=self.canvas.yview) self.canvas.configure(yscrollcommand=self.scrollbar.set) self.scrollbar.pack(side=tk.LEFT, fill=tk.Y) self.canvas.pack(side=tk.LEFT, expand=1, fill=tk.BOTH) self.friends_area = self.canvas.create_window((0, 0), window=self.canvas_frame, anchor="nw") self.bind_events() self.load_friends()
Example #4
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 6 votes |
def create_edit_menu(self): editMenu = tk.Menu(self.menubar) shapeMenu = tk.Menu(editMenu) editMenu.add_cascade(label=SHAPE, underline=0, menu=shapeMenu, image=self.images[SHAPE], compound=tk.LEFT) for name in sorted(Shapes.ShapeForName.keys()): shape = Shapes.ShapeForName[name] shapeMenu.add_radiobutton(label=shape.name, underline=shape.underline, value=shape.name, variable=self.shapeName, compound=tk.LEFT, image=self.images[shape.name]) if TkUtil.mac(): self.master.createcommand("::tk::mac::ShowPreferences", self.preferences) else: editMenu.add_command(label=PREFERENCES + ELLIPSIS, underline=0, command=self.preferences, image=self.images[PREFERENCES], compound=tk.LEFT) editMenu.add_checkbutton(label="Show Toolbar", underline=5, onvalue=True, offvalue=False, variable=self.showToolbar, command=self.toggle_toolbar) self.menubar.add_cascade(label="Edit", underline=0, menu=editMenu)
Example #5
Source File: texteditor.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
def generate_sub_menus(self, sub_menu_items): window_methods = [method_name for method_name in dir(self) if callable(getattr(self, method_name))] tkinter_methods = [method_name for method_name in dir(tk.Tk) if callable(getattr(tk.Tk, method_name))] my_methods = [method for method in set(window_methods) - set(tkinter_methods)] my_methods = sorted(my_methods) for item in sub_menu_items: sub_menu = tk.Menu(self.menu, tearoff=0, bg=self.background, fg=self.foreground) matching_methods = [] for method in my_methods: if method.startswith(item): matching_methods.append(method) for match in matching_methods: actual_method = getattr(self, match) method_shortcut = actual_method.__doc__.strip() friendly_name = ' '.join(match.split('_')[1:]) sub_menu.add_command(label=friendly_name.title(), command=actual_method, accelerator=method_shortcut) self.menu.add_cascade(label=item.title(), menu=sub_menu) self.all_menus.append(sub_menu)
Example #6
Source File: tree.py From razzy-spinner with GNU General Public License v3.0 | 6 votes |
def _init_menubar(self): menubar = Menu(self._top) filemenu = Menu(menubar, tearoff=0) filemenu.add_command(label='Print to Postscript', underline=0, command=self._cframe.print_to_file, accelerator='Ctrl-p') filemenu.add_command(label='Exit', underline=1, command=self.destroy, accelerator='Ctrl-x') menubar.add_cascade(label='File', underline=0, menu=filemenu) zoommenu = Menu(menubar, tearoff=0) zoommenu.add_radiobutton(label='Tiny', variable=self._size, underline=0, value=10, command=self.resize) zoommenu.add_radiobutton(label='Small', variable=self._size, underline=0, value=12, command=self.resize) zoommenu.add_radiobutton(label='Medium', variable=self._size, underline=0, value=14, command=self.resize) zoommenu.add_radiobutton(label='Large', variable=self._size, underline=0, value=28, command=self.resize) zoommenu.add_radiobutton(label='Huge', variable=self._size, underline=0, value=50, command=self.resize) menubar.add_cascade(label='Zoom', underline=0, menu=zoommenu) self._top.config(menu=menubar)
Example #7
Source File: texteditor.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
def generate_sub_menus(self, sub_menu_items): window_methods = [method_name for method_name in dir(self) if callable(getattr(self, method_name))] tkinter_methods = [method_name for method_name in dir(tk.Tk) if callable(getattr(tk.Tk, method_name))] my_methods = [method for method in set(window_methods) - set(tkinter_methods)] my_methods = sorted(my_methods) for item in sub_menu_items: sub_menu = tk.Menu(self.menu, tearoff=0, bg=self.background, fg=self.foreground) matching_methods = [] for method in my_methods: if method.startswith(item): matching_methods.append(method) for match in matching_methods: actual_method = getattr(self, match) method_shortcut = actual_method.__doc__.strip() friendly_name = ' '.join(match.split('_')[1:]) sub_menu.add_command(label=friendly_name.title(), command=actual_method, accelerator=method_shortcut) self.menu.add_cascade(label=item.title(), menu=sub_menu) self.all_menus.append(sub_menu)
Example #8
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 6 votes |
def create_file_menu(self): modifier = TkUtil.menu_modifier() fileMenu = tk.Menu(self.menubar, name="apple") fileMenu.add_command(label=NEW, underline=0, command=self.board.new_game, compound=tk.LEFT, image=self.images[NEW], accelerator=modifier + "+N") if TkUtil.mac(): self.master.createcommand("exit", self.close) self.master.createcommand("::tk::mac::ShowPreferences", self.preferences) else: fileMenu.add_separator() fileMenu.add_command(label=PREFERENCES + ELLIPSIS, underline=0, command=self.preferences, image=self.images[PREFERENCES], compound=tk.LEFT) fileMenu.add_separator() fileMenu.add_command(label="Quit", underline=0, command=self.close, compound=tk.LEFT, image=self.images[CLOSE], accelerator=modifier + "+Q") self.menubar.add_cascade(label="File", underline=0, menu=fileMenu)
Example #9
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 6 votes |
def create_file_menu(self): # Ctrl is nicer than Control for menus modifier = TkUtil.menu_modifier() fileMenu = tk.Menu(self.menubar, name="apple") fileMenu.add_command(label=NEW, underline=0, command=self.board.new_game, compound=tk.LEFT, image=self.images[NEW], accelerator=modifier + "+N") if TkUtil.mac(): self.master.createcommand("exit", self.close) else: fileMenu.add_separator() fileMenu.add_command(label="Quit", underline=0, command=self.close, compound=tk.LEFT, image=self.images[CLOSE], accelerator=modifier + "+Q") self.menubar.add_cascade(label="File", underline=0, menu=fileMenu)
Example #10
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 6 votes |
def update_recent_files_menu(self): if self.recentFiles: menu = tk.Menu(self.fileMenu) i = 1 for filename in self.recentFiles: if filename != self.editor.filename: menu.add_command(label="{}. {}".format(i, filename), underline=0, command=lambda filename=filename: self.load(filename)) i += 1 self.fileMenu.entryconfigure(OPEN_RECENT, menu=menu) self.fileMenu.entryconfigure(OPEN_RECENT, state=tk.NORMAL if i > 1 else tk.DISABLED) else: self.fileMenu.entryconfigure(OPEN_RECENT, state=tk.DISABLED)
Example #11
Source File: viewer.py From networkx_viewer with GNU General Public License v3.0 | 6 votes |
def _build_menu(self): self.menubar = tk.Menu(self) self.config(menu=self.menubar) view = tk.Menu(self.menubar, tearoff=0) view.add_command(label='Undo', command=self.canvas.undo, accelerator="Ctrl+Z") self.bind_all("<Control-z>", lambda e: self.canvas.undo()) # Implement accelerator view.add_command(label='Redo', command=self.canvas.redo) view.add_separator() view.add_command(label='Center on node...', command=self.center_on_node) view.add_separator() view.add_command(label='Reset Node Marks', command=self.reset_node_markings) view.add_command(label='Reset Edge Marks', command=self.reset_edge_markings) view.add_command(label='Redraw Plot', command=self.canvas.replot) view.add_separator() view.add_command(label='Grow display one level...', command=self.grow_all) self.menubar.add_cascade(label='View', menu=view)
Example #12
Source File: map-creator.py From rpg-text with MIT License | 6 votes |
def __init__(self, master, *args, **kwargs): kwargs['master'] = master super().__init__(*args, **kwargs) self.master = master self.help_window = None self.menubar = tk.Menu(self.master) self.menubar.add_command(label="Save", command=self._on_data_save) self.menubar.add_command(label="Load", command=self._on_data_load) self.menubar.add_command(label="Help", command=self._on_help) self.master.config(menu=self.menubar) self.form_frame = FormView(self) self.canvas = MapView(self, width=512, height=512, background='white') self.data = DataSerializer() master.bind('<Control-s>', self.data.save) master.bind('<Configure>', self.on_configure) self.setup_ui() self.loop()
Example #13
Source File: GUI_const_42_777_global.py From Python-GUI-Programming-Cookbook-Second-Edition with MIT License | 5 votes |
def _quit(): win.quit() win.destroy() exit() # Creating a Menu Bar
Example #14
Source File: views.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self, parent, settings, callbacks, **kwargs): """Constructor for MainMenu arguments: parent - The parent widget settings - a dict containing Tkinter variables callbacks - a dict containing Python callables """ super().__init__(parent, **kwargs) # The file menu file_menu = tk.Menu(self, tearoff=False) file_menu.add_command(label="Select file…", command=callbacks['file->select']) file_menu.add_separator() file_menu.add_command(label="Quit", command=callbacks['file->quit']) self.add_cascade(label='File', menu=file_menu) # The options menu options_menu = tk.Menu(self, tearoff=False) options_menu.add_checkbutton( label='Autofill Date', variable=settings['autofill date'] ) options_menu.add_checkbutton( label='Autofill Sheet data', variable=settings['autofill sheet data'] ) self.add_cascade(label='Options', menu=options_menu) # The help menu help_menu = tk.Menu(self, tearoff=False) help_menu.add_command(label='About…', command=self.show_about) self.add_cascade(label='Help', menu=help_menu)
Example #15
Source File: MainWindow.py From PyEngine3D with BSD 2-Clause "Simplified" License | 5 votes |
def set_window_title(self, title): self.root.title(title) # ------------------------- # # Menu # ------------------------- #
Example #16
Source File: view.py From ms_deisotope with Apache License 2.0 | 5 votes |
def configure_toolbar(self): self.toolbar = tk.Menu(self) self.toolbar.add_command(label='Open', command=self.select_ms_file) self.toolbar.add_command(label='Interact', command=self._interact) self.root.config(menu=self.toolbar)
Example #17
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 5 votes |
def create_menubar(self): self.menubar = tk.Menu(self.master) self.master.config(menu=self.menubar) self.create_file_menu() self.create_edit_menu() self.create_help_menu()
Example #18
Source File: GUI_const_42.py From Python-GUI-Programming-Cookbook-Second-Edition with MIT License | 5 votes |
def _quit(): win.quit() win.destroy() exit() # Creating a Menu Bar
Example #19
Source File: GUI_const_42_777_global.py From Python-GUI-Programming-Cookbook-Second-Edition with MIT License | 5 votes |
def _msgBox(): msg.showinfo('Python Message Info Box', 'A Python GUI created using tkinter:\nThe year is 2017.') # Add another Menu to the Menu Bar and an item
Example #20
Source File: GUI_const_42_777_global_print.py From Python-GUI-Programming-Cookbook-Second-Edition with MIT License | 5 votes |
def _quit(): win.quit() win.destroy() exit() # Creating a Menu Bar
Example #21
Source File: GUI_data_from_widget.py From Python-GUI-Programming-Cookbook-Second-Edition with MIT License | 5 votes |
def _msgBox(): msg.showinfo('Python Message Info Box', 'A Python GUI created using tkinter:\nThe year is 2017.') # Add another Menu to the Menu Bar and an item
Example #22
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 5 votes |
def create_help_menu(self): helpMenu = tk.Menu(self.menubar, name="help") if TkUtil.mac(): self.master.createcommand("tkAboutDialog", self.about) self.master.createcommand("::tk::mac::ShowHelp", self.help) else: helpMenu.add_command(label=HELP, underline=0, command=self.help, image=self.images[HELP], compound=tk.LEFT, accelerator="F1") helpMenu.add_command(label=ABOUT, underline=0, command=self.about, image=self.images[ABOUT], compound=tk.LEFT) self.menubar.add_cascade(label=HELP, underline=0, menu=helpMenu)
Example #23
Source File: GUI_const_42_777.py From Python-GUI-Programming-Cookbook-Second-Edition with MIT License | 5 votes |
def _quit(): win.quit() win.destroy() exit() # Creating a Menu Bar
Example #24
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 5 votes |
def context_menu(self, event): modifier = TkUtil.menu_modifier() menu = tk.Menu(self.master) if self.editor.text.tag_ranges(tk.SEL): menu.add_command(label=COPY, underline=0, command=lambda: self.editor.text.event_generate( "<<Copy>>"), image=self.menuImages[COPY], compound=tk.LEFT, accelerator=modifier + "+C") menu.add_command(label=CUT, underline=2, command=lambda: self.editor.text.event_generate( "<<Cut>>"), image=self.menuImages[CUT], compound=tk.LEFT, accelerator=modifier + "+X") menu.add_command(label=PASTE, underline=0, command=lambda: self.editor.text.event_generate( "<<Paste>>"), image=self.menuImages[PASTE], compound=tk.LEFT, accelerator=modifier + "+V") menu.add_separator() menu.add_checkbutton(label=BOLD, underline=0, image=self.menuImages[BOLD], compound=tk.LEFT, variable=self.bold, command=lambda: self.toggle_button(self.boldButton)) menu.add_checkbutton(label=ITALIC, underline=0, image=self.menuImages[ITALIC], compound=tk.LEFT, variable=self.italic, command=lambda: self.toggle_button(self.italicButton)) menu.add_separator() menu.add_radiobutton(label=ALIGN_LEFT, underline=6, image=self.menuImages[ALIGNLEFT], compound=tk.LEFT, variable=self.alignment, value=tk.LEFT, command=self.toggle_alignment) menu.add_radiobutton(label=ALIGN_CENTER, underline=6, image=self.menuImages[ALIGNCENTER], compound=tk.LEFT, variable=self.alignment, value=tk.CENTER, command=self.toggle_alignment) menu.add_radiobutton(label=ALIGN_RIGHT, underline=6, image=self.menuImages[ALIGNRIGHT], compound=tk.LEFT, variable=self.alignment, value=tk.RIGHT, command=self.toggle_alignment) menu.tk_popup(event.x_root, event.y_root)
Example #25
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 5 votes |
def create_dock_window_menu(self): self.dockWindowMenu = tk.Menu(self.windowMenu) for dockWindow in self.dockWindows: self.dockWindowMenu.add_checkbutton(label=dockWindow.title, underline=dockWindow.underline, variable=dockWindow.visible, onvalue=True, offvalue=False) self.windowMenu.entryconfigure("Dock Windows", menu=self.dockWindowMenu)
Example #26
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 5 votes |
def toolbar_menu(self, event=None): if self.toolbarMenu is None: self.toolbarMenu = tk.Menu(self.toolbarMenu) for toolbar in self.toolbars: self.toolbarMenu.add_checkbutton(label=toolbar.text, underline=toolbar.underline, variable=toolbar.visible, onvalue=True, offvalue=False) self.toolbarMenu.tk_popup(self.winfo_pointerx(), self.winfo_pointery())
Example #27
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 5 votes |
def create_alignment_toolbar(self): settings = TkUtil.Settings.Data self.alignmentToolbar = ttk.Frame(self.toolbarFrame, relief=tk.RAISED) self.alignmentToolbar.text = ALIGNMENT_TOOLBAR self.alignmentToolbar.underline = 0 menuButton = ttk.Button(self.alignmentToolbar, text="Alignment Toolbar Menu", image=self.toolbarImages[TOOLBARMENU], command=self.toolbar_menu) TkUtil.bind_context_menu(menuButton, self.toolbar_menu) TkUtil.Tooltip.Tooltip(menuButton, text="Alignment Toolbar Menu") self.leftButton = ttk.Button(self.alignmentToolbar, text=ALIGN_LEFT, image=self.toolbarImages[ALIGNLEFT]) self.leftButton.config( command=lambda: self.toggle_alignment(tk.LEFT)) TkUtil.Tooltip.Tooltip(self.leftButton, text=ALIGN_LEFT) self.centerButton = ttk.Button(self.alignmentToolbar, text=ALIGN_CENTER, image=self.toolbarImages[ALIGNCENTER]) self.centerButton.config( command=lambda: self.toggle_alignment(tk.CENTER)) TkUtil.Tooltip.Tooltip(self.centerButton, text=ALIGN_CENTER) self.rightButton = ttk.Button(self.alignmentToolbar, text=ALIGN_RIGHT, image=self.toolbarImages[ALIGNRIGHT]) self.rightButton.config( command=lambda: self.toggle_alignment(tk.RIGHT)) TkUtil.Tooltip.Tooltip(self.rightButton, text=ALIGN_RIGHT) TkUtil.add_toolbar_buttons(self.alignmentToolbar, (menuButton, self.leftButton, self.centerButton, self.rightButton)) self.toolbars.append(self.alignmentToolbar) self.leftButton.state((TkUtil.SELECTED,)) self.alignment.set(tk.LEFT)
Example #28
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 5 votes |
def create_file_toolbar(self): settings = TkUtil.Settings.Data self.fileToolbar = ttk.Frame(self.toolbarFrame, relief=tk.RAISED) self.fileToolbar.text = FILE_TOOLBAR self.fileToolbar.underline = 0 menuButton = ttk.Button(self.fileToolbar, text="File Toolbar Menu", image=self.toolbarImages[TOOLBARMENU], command=self.toolbar_menu) TkUtil.bind_context_menu(menuButton, self.toolbar_menu) TkUtil.Tooltip.Tooltip(menuButton, text="File Toolbar Menu") newButton = ttk.Button(self.fileToolbar, text=NEW, image=self.toolbarImages[NEW], command=self.new) TkUtil.Tooltip.Tooltip(newButton, text="New Document") openButton = ttk.Button(self.fileToolbar, text=OPEN, image=self.toolbarImages[OPEN], command=self.open) TkUtil.Tooltip.Tooltip(openButton, text="Open Document") self.saveButton = ttk.Button(self.fileToolbar, text=SAVE, image=self.toolbarImages[SAVE], command=self.save) TkUtil.Tooltip.Tooltip(self.saveButton, text="Save Document") preferencesButton = ttk.Button(self.fileToolbar, text=PREFERENCES, image=self.toolbarImages[PREFERENCES], command=self.preferences) TkUtil.Tooltip.Tooltip(preferencesButton, text=PREFERENCES) TkUtil.add_toolbar_buttons(self.fileToolbar, (menuButton, newButton, openButton, self.saveButton, None, preferencesButton)) self.toolbars.append(self.fileToolbar)
Example #29
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 5 votes |
def create_help_menu(self): helpMenu = tk.Menu(self.menubar, name="help") if TkUtil.mac(): self.master.createcommand("tkAboutDialog", self.about) self.master.createcommand("::tk::mac::ShowHelp", self.help) else: helpMenu.add_command(label=HELP, underline=0, command=self.help, image=self.menuImages[HELP], compound=tk.LEFT, accelerator="F1") helpMenu.add_command(label=ABOUT, underline=0, command=self.about, image=self.menuImages[ABOUT], compound=tk.LEFT) self.menubar.add_cascade(label=HELP, underline=0, menu=helpMenu)
Example #30
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 5 votes |
def create_window_menu(self): modifier = TkUtil.menu_modifier() self.windowMenu = tk.Menu(self.menubar, name="window") self.windowToolbarMenu = tk.Menu(self.windowMenu) self.windowMenu.add_cascade(label="Toolbars", underline=0, menu=self.windowToolbarMenu) self.windowMenu.add_cascade(label="Dock Windows", underline=0) self.menubar.add_cascade(label="Window", underline=0, menu=self.windowMenu)