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: 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 #2
Source File: refbrowser.py From pyFileFixity with MIT License | 6 votes |
def drawtext(self): """Override drawtext from _TreeWidget.TreeNode. This seems to be a good place to add the popup menu. """ _TreeWidget.TreeNode.drawtext(self) # create a menu menu = _Tkinter.Menu(self.canvas, tearoff=0) menu.add_command(label="reload referrers", command=self.reload_referrers) menu.add_command(label="print", command=self.print_object) menu.add_separator() menu.add_command(label="expand", command=self.expand) menu.add_separator() # the popup only disappears when to click on it menu.add_command(label="Close Popup Menu") def do_popup(event): menu.post(event.x_root, event.y_root) self.label.bind("<Button-3>", do_popup) # override, i.e. disable the editing of items # disable editing of TreeNodes def edit(self, event=None): pass #PYCHOK see comment above def edit_finish(self, event=None): pass #PYCHOK see comment above def edit_cancel(self, event=None): pass #PYCHOK see comment above
Example #3
Source File: gui.py From stochopy with MIT License | 6 votes |
def menubar(self): menubar = tk.Menu(self.master) # File filemenu = tk.Menu(menubar, tearoff = 0) filemenu.add_command(label = "Export models", command = self.export_models) filemenu.add_command(label = "Export fitness", command = self.export_fitness) filemenu.add_separator() filemenu.add_command(label = "Exit", command = self.close_window) # Help helpmenu = tk.Menu(menubar, tearoff = 0) helpmenu.add_command(label = "About", command = self.about) # Display menu bar menubar.add_cascade(label = "File", menu = filemenu) menubar.add_cascade(label = "Help", menu = helpmenu) self.master.config(menu = menubar)
Example #4
Source File: GUI.py From Scoary with GNU General Public License v3.0 | 6 votes |
def initialize_menu(self): """ Initialize the menu at the top """ self.menubar = Tkinter.Menu(self,relief="flat") filemenu = Tkinter.Menu(self.menubar,tearoff=0) filemenu.add_command(label="About",command=self.AboutScoary) filemenu.add_separator() filemenu.add_command(label="Quit",command=self.quit) self.filemenu = filemenu self.menubar.add_cascade(label="File",menu=self.filemenu) optsmenu = Tkinter.Menu(self.menubar,tearoff=0) optsmenu.add_command(label="Clear", command=self.ClearAll) optsmenu.add_command(label="Test example", command=self.TestExample) self.optsmenu = optsmenu self.menubar.add_cascade(label="Options",menu=self.optsmenu) self.config(menu=self.menubar)
Example #5
Source File: tkmktap.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def __init__(self, master, create, callback, items): Tkinter.Menu.__init__(self, master) cmdMenu = Tkinter.Menu(self) self.add_cascade(label="Actions", menu=cmdMenu) cmdMenu.add_command(label='Create', command=create) cmdMenu.add_separator() cmdMenu.add_command(label='Quit', command=reactor.crash) tapMenu = Tkinter.Menu(self) self.add_cascade(label="Applications", menu=tapMenu) for item in items: tapMenu.add_command( label=item, command=lambda i=item, c = callback: c(i) )
Example #6
Source File: guiClass.py From Video-Downloader with GNU General Public License v2.0 | 6 votes |
def __menu (self) : menubar = Tkinter.Menu(self.master) fileMenu = Tkinter.Menu(menubar, tearoff = 0) fileMenu.add_command(label = "Config", command = self.__configPanel) fileMenu.add_command(label = "Close", command = self.master.quit) menubar.add_cascade(label = "File", menu = fileMenu) aboutMenu = Tkinter.Menu(menubar, tearoff = 0) aboutMenu.add_command(label = "Info", command = self.__showInfo) aboutMenu.add_command(label = "Check Update", command = self.__chkUpdate) menubar.add_cascade(label = "About", menu = aboutMenu) helpMenu = Tkinter.Menu(menubar, tearoff = 0) helpMenu.add_command(label = "GitHub", command = lambda target = self.gitUrl : webbrowser.open_new(target)) helpMenu.add_command(label = "Release Notes", command = lambda target = self.appUrl : webbrowser.open_new(target)) helpMenu.add_command(label = "Send Feedback", command = lambda target = self.feedUrl : webbrowser.open_new(target)) menubar.add_cascade(label = "Help", menu = helpMenu) self.master.config(menu = menubar)
Example #7
Source File: tree.py From luscan-devel with GNU General Public License v2.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 #8
Source File: 03_Organizing_with_Frames.py From MacAdmins-2016-Craft-GUIs-with-Python-and-Tkinter with MIT License | 6 votes |
def __init__(self, master): tk.Frame.__init__(self, master) self.pack() self.master.title("Hello World") self.master.resizable(False, False) self.master.tk_setPalette(background='#ececec') x = (self.master.winfo_screenwidth() - self.master.winfo_reqwidth()) / 2 y = (self.master.winfo_screenheight() - self.master.winfo_reqheight()) / 3 self.master.geometry("+{}+{}".format(x, y)) self.master.config(menu=tk.Menu(self.master)) dialog_frame = tk.Frame(self) dialog_frame.pack(padx=20, pady=15) tk.Label(dialog_frame, text="This is your first GUI. (highfive)").pack() button_frame = tk.Frame(self) button_frame.pack(padx=15, pady=(0, 15), anchor='e') tk.Button(button_frame, text='OK', default='active', command=self.click_ok).pack(side='right') tk.Button(button_frame, text='Cancel', command=self.click_cancel).pack(side='right')
Example #9
Source File: 05_Password_Prompt.py From MacAdmins-2016-Craft-GUIs-with-Python-and-Tkinter with MIT License | 5 votes |
def __init__(self, master): tk.Frame.__init__(self, master) self.pack() self.master.title("") self.master.resizable(False, False) self.master.tk_setPalette(background='#ececec') self.master.protocol('WM_DELETE_WINDOW', self.click_cancel) self.master.bind('<Return>', self.click_ok) self.master.bind('<Escape>', self.click_cancel) x = (self.master.winfo_screenwidth() - self.master.winfo_reqwidth()) / 2 y = (self.master.winfo_screenheight() - self.master.winfo_reqheight()) / 3 self.master.geometry("+{}+{}".format(x, y)) self.master.config(menu=tk.Menu(self)) tk.Message(self, text="Please authenticate with your username and password before continuing.", font='System 14 bold', justify='left', aspect=800).pack(pady=(15, 0)) dialog_frame = tk.Frame(self) dialog_frame.pack(padx=20, pady=15, anchor='w') tk.Label(dialog_frame, text='Username:').grid(row=0, column=0, sticky='w') self.user_input = tk.Entry(dialog_frame, background='white', width=24) self.user_input.grid(row=0, column=1, sticky='w') self.user_input.focus_set() tk.Label(dialog_frame, text='Password:').grid(row=1, column=0, sticky='w') self.pass_input = tk.Entry(dialog_frame, background='white', width=24, show='*') self.pass_input.grid(row=1, column=1, sticky='w') button_frame = tk.Frame(self) button_frame.pack(padx=15, pady=(0, 15), anchor='e') tk.Button(button_frame, text='OK', height=1, width=6, default='active', command=self.click_ok).pack(side='right') tk.Button(button_frame, text='Cancel', height=1, width=6, command=self.click_cancel).pack(side='right', padx=10)
Example #10
Source File: graph_canvas.py From networkx_viewer with GNU General Public License v3.0 | 5 votes |
def onTokenRightClick(self, event): item = self._get_id(event) popup = tk.Menu(self, tearoff=0) popup.add_command(label='Grow', command=lambda: self.grow_node(item), accelerator='G') popup.add_command(label='Grow until...', command=lambda: self.grow_until(item)) popup.add_command(label='Mark', command=lambda: self.mark_node(item), accelerator='M') popup.add_command(label='Hide', command=lambda: self.hide_node(item), accelerator='H') hide_behind = tk.Menu(popup, tearoff=0) for _, n in self.dispG.edges_iter(item): assert _ == item if self._radial_behind(item, n): state = tk.ACTIVE else: state = tk.DISABLED hide_behind.add_command(label=str(self.dispG.node[n]['dataG_id']), state=state, command=lambda item=item, n=n: self.hide_behind(item, n)) popup.add_cascade(label='Hide Behind', menu=hide_behind) token = self.dispG.node[item]['token'] token.customize_menu(popup, item) try: popup.post(event.x_root, event.y_root) finally: popup.grab_release()
Example #11
Source File: chartparser_app.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def about(self, *e): ABOUT = ("NLTK Chart Parser Application\n"+ "Written by Edward Loper") tkMessageBox.showinfo('About: Chart Parser Application', ABOUT) #//////////////////////////////////////////////////////////// # File Menu #////////////////////////////////////////////////////////////
Example #12
Source File: chartparser_app.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def set_sentence(self, sentence): self._tokens = list(sentence.split()) self.reset() #//////////////////////////////////////////////////////////// # View Menu #////////////////////////////////////////////////////////////
Example #13
Source File: chartparser_app.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def view_results(self, *e): if self._results is not None: self._results.destroy() self._results = ChartResultsView(self._root, self._chart, self._grammar) #//////////////////////////////////////////////////////////// # Zoom Menu #////////////////////////////////////////////////////////////
Example #14
Source File: configurator.py From Enrich2 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def create_treeview_context_menu(self): self.treeview_popup = tk.Menu(self, tearoff=0) self.treeview_popup.add_command( label="Apply FASTQ...", command=self.apply_seqlib_fastq )
Example #15
Source File: ttk.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, master, variable, default=None, *values, **kwargs): """Construct a themed OptionMenu widget with master as the parent, the resource textvariable set to variable, the initially selected value specified by the default parameter, the menu values given by *values and additional keywords. WIDGET-SPECIFIC OPTIONS style: stylename Menubutton style. direction: 'above', 'below', 'left', 'right', or 'flush' Menubutton direction. command: callback A callback that will be invoked after selecting an item. """ kw = {'textvariable': variable, 'style': kwargs.pop('style', None), 'direction': kwargs.pop('direction', None)} Menubutton.__init__(self, master, **kw) self['menu'] = Tkinter.Menu(self, tearoff=False) self._variable = variable self._callback = kwargs.pop('command', None) if kwargs: raise Tkinter.TclError('unknown option -%s' % ( kwargs.iterkeys().next())) self.set_menu(default, *values)
Example #16
Source File: help.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def toc_menu(self, text): "Create table of contents as drop-down menu." toc = Menubutton(self, text='TOC') drop = Menu(toc, tearoff=False) for lbl, dex in text.parser.toc: drop.add_command(label=lbl, command=lambda dex=dex:text.yview(dex)) toc['menu'] = drop return toc
Example #17
Source File: 01_Basic_Appearance.py From MacAdmins-2016-Craft-GUIs-with-Python-and-Tkinter with MIT License | 5 votes |
def __init__(self, master): tk.Frame.__init__(self, master) self.pack() self.master.title("Hello World") self.master.resizable(False, False) self.master.tk_setPalette(background='#ececec') # '#ececec' is the standard gray background of El Capitain x = (self.master.winfo_screenwidth() - self.master.winfo_reqwidth()) / 2 y = (self.master.winfo_screenheight() - self.master.winfo_reqheight()) / 3 self.master.geometry("+{}+{}".format(x, y)) self.master.config(menu=tk.Menu(self)) tk.Label(self, text="This is your first GUI. (highfive)").pack()
Example #18
Source File: chartparser_app.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def _init_menubar(self, root): menubar = Tkinter.Menu(root) # File menu filemenu = Tkinter.Menu(menubar, tearoff=0) filemenu.add_command(label='Load Chart', accelerator='Ctrl-o', underline=0, command=self.load_chart_dialog) filemenu.add_command(label='Save Output', accelerator='Ctrl-s', underline=0, command=self.save_chart_dialog) filemenu.add_separator() filemenu.add_command(label='Exit', underline=1, command=self.destroy, accelerator='Ctrl-x') menubar.add_cascade(label='File', underline=0, menu=filemenu) # Compare menu opmenu = Tkinter.Menu(menubar, tearoff=0) opmenu.add_command(label='Intersection', command=self._intersection, accelerator='+') opmenu.add_command(label='Union', command=self._union, accelerator='*') opmenu.add_command(label='Difference', command=self._difference, accelerator='-') opmenu.add_separator() opmenu.add_command(label='Swap Charts', command=self._swapcharts) menubar.add_cascade(label='Compare', underline=0, menu=opmenu) # Add the menu self._root.config(menu=menubar)
Example #19
Source File: 04_The_Boilerplate.py From MacAdmins-2016-Craft-GUIs-with-Python-and-Tkinter with MIT License | 5 votes |
def __init__(self, master): tk.Frame.__init__(self, master) self.pack() self.master.title("Hello World") self.master.resizable(False, False) self.master.tk_setPalette(background='#ececec') self.master.protocol('WM_DELETE_WINDOW', self.click_cancel) self.master.bind('<Return>', self.click_ok) self.master.bind('<Escape>', self.click_cancel) x = (self.master.winfo_screenwidth() - self.master.winfo_reqwidth()) / 2 y = (self.master.winfo_screenheight() - self.master.winfo_reqheight()) / 3 self.master.geometry("+{}+{}".format(x, y)) self.master.config(menu=tk.Menu(self.master)) dialog_frame = tk.Frame(self) dialog_frame.pack(padx=20, pady=15) tk.Label(dialog_frame, text="This is your first GUI. (highfive)").pack() button_frame = tk.Frame(self) button_frame.pack(padx=15, pady=(0, 15), anchor='e') tk.Button(button_frame, text='OK', default='active', command=self.click_ok).pack(side='right') tk.Button(button_frame, text='Cancel', command=self.click_cancel).pack(side='right')
Example #20
Source File: gui_batchdownload.py From grab_huaban_board with BSD 3-Clause "New" or "Revised" License | 5 votes |
def popup1(event, *args, **kwargs): Popupmenu1 = tk.Menu(root, tearoff=0) Popupmenu1.configure(activebackground="#f9f9f9") Popupmenu1.configure(activeborderwidth="1") Popupmenu1.configure(activeforeground="black") Popupmenu1.configure(background="#d9d9d9") Popupmenu1.configure(borderwidth="1") Popupmenu1.configure(disabledforeground="#a3a3a3") Popupmenu1.configure(font="{Microsoft YaHei UI} 9") Popupmenu1.configure(foreground="black") Popupmenu1.post(event.x_root, event.y_root)
Example #21
Source File: gui_batchdownload.py From grab_huaban_board with BSD 3-Clause "New" or "Revised" License | 5 votes |
def popup2(event, *args, **kwargs): Popupmenu2 = tk.Menu(root, tearoff=0) Popupmenu2.configure(activebackground="#f9f9f9") Popupmenu2.configure(activeborderwidth="1") Popupmenu2.configure(activeforeground="black") Popupmenu2.configure(background="#d9d9d9") Popupmenu2.configure(borderwidth="1") Popupmenu2.configure(disabledforeground="#a3a3a3") Popupmenu2.configure(font="{Microsoft YaHei UI} 9") Popupmenu2.configure(foreground="black") Popupmenu2.post(event.x_root, event.y_root)
Example #22
Source File: grid_box.py From PCWG with MIT License | 5 votes |
def __init__(self, master, headers, row, column): self.master = master self.headers = headers self.items_dict = {} self.tree = None self.container = ttk.Frame(self.master) self.container.grid(row=row, column=column, sticky=tk.W+tk.E+tk.N+tk.S) self._set_up_tree_widget() self._build_tree() # create a popup menu self.pop_menu = tk.Menu(self.tree, tearoff=0) self.pop_menu.add_command(label="New", command=self.new) self.pop_menu.add_command(label="Remove", command=self.remove) self.pop_menu.add_command(label="Remove All", command=self.remove_all) self.pop_menu.add_command(label="Edit", command=self.edit) self.pop_menu_add = tk.Menu(self.tree, tearoff=0) self.pop_menu_add.add_command(label="New", command=self.new) self.pop_menu_add.add_command(label="Remove All", command=self.remove_all) self.tree.bind("<Button-2>", self.pop_up) self.tree.bind("<Button-3>", self.pop_up) self.onChange = EventHook() self.tip = None
Example #23
Source File: test_widgets.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_menu(self): widget = self.create() menu = tkinter.Menu(widget, name='menu') self.checkParam(widget, 'menu', menu, conv=str) menu.destroy()
Example #24
Source File: test_widgets.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_menu(self): widget = self.create() menu = tkinter.Menu(self.root) self.checkParam(widget, 'menu', menu, eq=widget_eq) self.checkParam(widget, 'menu', '')
Example #25
Source File: test_widgets.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_menu(self): widget = self.create() menu = tkinter.Menu(widget, name='menu') self.checkParam(widget, 'menu', menu, eq=widget_eq) menu.destroy()
Example #26
Source File: test_widgets.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def create(self, **kwargs): return tkinter.Menu(self.root, **kwargs)
Example #27
Source File: pykms_GuiBase.py From py-kms with The Unlicense | 5 votes |
def gui_menu(self): self.onlysrv, self.onlyclt = (False for _ in range(2)) menubar = tk.Menu(self) prefmenu = tk.Menu(menubar, tearoff = 0, font = ("Noto Sans Regular", 10), borderwidth = 3, relief = 'ridge') menubar.add_cascade(label = 'Preferences', menu = prefmenu) prefmenu.add_command(label = 'Enable server-side mode', command = lambda: self.pref_onlysrv(prefmenu)) prefmenu.add_command(label = 'Enable client-side mode', command = lambda: self.pref_onlyclt(prefmenu)) self.config(menu = menubar)
Example #28
Source File: graph_canvas.py From networkx_viewer with GNU General Public License v3.0 | 5 votes |
def onEdgeRightClick(self, event): item = self._get_id(event, 'edge') for u,v,k,d in self.dispG.edges_iter(keys=True, data=True): if d['token'].id == item: break popup = tk.Menu(self, tearoff=0) popup.add_command(label='Mark', command=lambda: self.mark_edge(u,v,k)) d['token'].customize_menu(popup) try: popup.post(event.x_root, event.y_root) finally: popup.grab_release()
Example #29
Source File: chart.py From razzy-spinner with GNU General Public License v3.0 | 5 votes |
def _init_menubar(self, root): menubar = Tkinter.Menu(root) # File menu filemenu = Tkinter.Menu(menubar, tearoff=0) filemenu.add_command(label='Load Chart', accelerator='Ctrl-o', underline=0, command=self.load_chart_dialog) filemenu.add_command(label='Save Output', accelerator='Ctrl-s', underline=0, command=self.save_chart_dialog) filemenu.add_separator() filemenu.add_command(label='Exit', underline=1, command=self.destroy, accelerator='Ctrl-x') menubar.add_cascade(label='File', underline=0, menu=filemenu) # Compare menu opmenu = Tkinter.Menu(menubar, tearoff=0) opmenu.add_command(label='Intersection', command=self._intersection, accelerator='+') opmenu.add_command(label='Union', command=self._union, accelerator='*') opmenu.add_command(label='Difference', command=self._difference, accelerator='-') opmenu.add_separator() opmenu.add_command(label='Swap Charts', command=self._swapcharts) menubar.add_cascade(label='Compare', underline=0, menu=opmenu) # Add the menu self._root.config(menu=menubar)
Example #30
Source File: chart.py From razzy-spinner with GNU General Public License v3.0 | 5 votes |
def about(self, *e): ABOUT = ("NLTK Chart Parser Demo\n"+ "Written by Edward Loper") tkMessageBox.showinfo('About: Chart Parser Demo', ABOUT) #//////////////////////////////////////////////////////////// # File Menu #////////////////////////////////////////////////////////////