本文整理汇总了Python中tkinter.Menu.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Menu.delete方法的具体用法?Python Menu.delete怎么用?Python Menu.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Menu
的用法示例。
在下文中一共展示了Menu.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TopMenuBar
# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import delete [as 别名]
class TopMenuBar(Menu):
def __init__(self, parent):
Menu.__init__(self, parent)
self.parent = parent
self.newmenu = Menu(self)
self.showmenu = Menu(self)
self.added_buttons = []
self.newmenu.add_command(label="NPC", command=self.parent.onNew)
self.newmenu.add_separator()
self.newmenu.add_command(label="Save", command=self.parent.save)
self.newmenu.add_command(label="Load", command=self.parent.load)
self.showmenu.add_command(label="Info", command=self.parent.get_info)
self.showmenu.add_command(label="Save Image", command=self.parent.save_image)
self.newmenu.add_separator()
self.showmenu.add_separator()
self.add_cascade(label="New", menu=self.newmenu)
self.add_cascade(label="Show", menu=self.showmenu)
self.add_command(label="Exit", command=self.parent.quit)
def add_button(self, menu, name, call):
func = partial(call, name)
if menu == "new":
self.newmenu.add_command(label=name, command=func)
elif menu == "show":
self.showmenu.add_command(label=name, command=func)
self.added_buttons.append(name)
def remove_all(self):
for but in self.added_buttons:
self.remove_item(name)
def remove_item(self, name):
self.showmenu.delete(name)
示例2: accounts_postcommand
# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import delete [as 别名]
def accounts_postcommand(menu: tk.Menu):
"""Update the accounts menu whenever the user clicks on the menu bar.
Args:
menu: The accounts menu.
This will delete every menu item from the second item to the end. Each account will be
added showing a combination of institution and account name.
Menu postcommands are subordinate to the main menu in the module hierarchy so are best
placed in the main menu module.
"""
start_item_ix = 2
menu.delete(start_item_ix, menu.index(tk.END))
inst_name_accs = sorted([("{} {}…".format(acc.inst, acc.name), acc)
for acc in config.data.accs])
for inst_name, acc in inst_name_accs:
menu.add_command(label=inst_name,
command=lambda acc=acc: accountsmenu.account_edit(acc),
state=tk.ACTIVE)
示例3: ShiftReduceApp
# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import delete [as 别名]
#.........这里部分代码省略.........
#self._rtextlabel['font'] = ('helvetica', -size-4, 'bold')
#self._lastoper_label['font'] = ('helvetica', -size)
#self._lastoper1['font'] = ('helvetica', -size)
#self._lastoper2['font'] = ('helvetica', -size)
#self._prodlist['font'] = ('helvetica', -size)
#self._prodlist_label['font'] = ('helvetica', -size-2, 'bold')
self._redraw()
def help(self, *e):
# The default font's not very legible; try using 'fixed' instead.
try:
ShowText(self._top, 'Help: Shift-Reduce Parser Application',
(__doc__ or '').strip(), width=75, font='fixed')
except:
ShowText(self._top, 'Help: Shift-Reduce Parser Application',
(__doc__ or '').strip(), width=75)
def about(self, *e):
ABOUT = ("NLTK Shift-Reduce Parser Application\n"+
"Written by Edward Loper")
TITLE = 'About: Shift-Reduce Parser Application'
try:
from tkinter.messagebox import Message
Message(message=ABOUT, title=TITLE).show()
except:
ShowText(self._top, TITLE, ABOUT)
def edit_grammar(self, *e):
CFGEditor(self._top, self._parser.grammar(), self.set_grammar)
def set_grammar(self, grammar):
self._parser.set_grammar(grammar)
self._productions = list(grammar.productions())
self._prodlist.delete(0, 'end')
for production in self._productions:
self._prodlist.insert('end', (' %s' % production))
def edit_sentence(self, *e):
sentence = " ".join(self._sent)
title = 'Edit Text'
instr = 'Enter a new sentence to parse.'
EntryDialog(self._top, sentence, instr, self.set_sentence, title)
def set_sentence(self, sent):
self._sent = sent.split() #[XX] use tagged?
self.reset()
#########################################
## Reduce Production Selection
#########################################
def _toggle_grammar(self, *e):
if self._show_grammar.get():
self._prodframe.pack(fill='both', side='left', padx=2,
after=self._feedbackframe)
self._lastoper1['text'] = 'Show Grammar'
else:
self._prodframe.pack_forget()
self._lastoper1['text'] = 'Hide Grammar'
self._lastoper2['text'] = ''
def _prodlist_select(self, event):
selection = self._prodlist.curselection()
if len(selection) != 1: return
index = int(selection[0])
production = self._parser.reduce(self._productions[index])
示例4: CimApp
# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import delete [as 别名]
#.........这里部分代码省略.........
self.menu_help.add_separator()
self.menu_help.add_command(label="README",
command=self.help_readme,
underline=0)
self.menu_help.add_separator()
self.menu_help.add_command(label="About",
command=self.help_about,
underline=0)
self.menubar.add_cascade(label="Help",
menu=self.menu_help,
underline=0)
self.master.config(width=450,
height=400,
menu=self.menubar)
self.bind_all("<Control-o>", self.load_file)
self.bind_all("<Control-s>", self.file_save)
self.bind_all("<Control-Alt-s>", self.file_save_as)
self.bind_all("<Control-t>", self.convert_file)
self.bind_all("<Control-b>", self.flash_file)
self.bind_all("<Control-w>", self.close_file)
self.master.protocol("WM_DELETE_WINDOW", self.file_quit)
self.file_tabs = Notebook(self)
self.file_tabs.bind_all("<<NotebookTabChanged>>", self.file_changed)
self.file_tabs.pack(expand=1, fill="both")
def file_changed(self, event):
if len(self.file_tabs.tabs()) <= 0:
self.add_file()
return
title = str(event.widget.tab(event.widget.index("current"),"text")).upper().strip()
self.menu_program.delete(3, END)
for tab in self.file_tabs.tabs():
tabtext = self.file_tabs.tab(self.file_tabs.index(tab),"text")
if tabtext.upper().strip() == title:
self.current_tab.set(tab)
self.menu_program.add_radiobutton(label=tabtext, command=self.program_switch,
underline=1, value=tab, variable=self.current_tab)
if title != "PYTHON" or title != "TIBORCIM":
if self.current_file().filename is not None:
self.master.title(self.current_file().get_file() + " - Tiborcim")
else:
self.master.title("Tiborcim")
if str(self.current_file().tab(self.current_file().index("current"),"text")).upper().strip() == "TIBORCIM":
self.menubar.entryconfig("Edit", state=NORMAL)
else:
self.menubar.entryconfig("Edit", state=DISABLED)
self.viewmode.set(self.current_file().viewmode)
if title == "PYTHON":
self.menubar.entryconfig("Edit", state=DISABLED)
self.current_file().viewmode = "python";
self.viewmode.set("python");
if title == "TIBORCIM":
self.menubar.entryconfig("Edit", state=NORMAL)
self.current_file().viewmode = "tiborcim";
self.viewmode.set("tiborcim");
def add_file(self, file=None):
filepage = CimFilePage(self.file_tabs)
if file is None:
self.file_tabs.add(filepage, text="Unsaved Program")
else:
filepage.load_file(file)
self.file_tabs.add(filepage, text=filepage.get_file())