当前位置: 首页>>代码示例>>Python>>正文


Python tkinter.Menu方法代码示例

本文整理汇总了Python中tkinter.Menu方法的典型用法代码示例。如果您正苦于以下问题:Python tkinter.Menu方法的具体用法?Python tkinter.Menu怎么用?Python tkinter.Menu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter的用法示例。


在下文中一共展示了tkinter.Menu方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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() 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:22,代码来源:friendslist.py

示例2: generate_sub_menus

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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) 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:26,代码来源:texteditor.py

示例3: _build_menu

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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) 
开发者ID:jsexauer,项目名称:networkx_viewer,代码行数:20,代码来源:viewer.py

示例4: _init_menubar

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:27,代码来源:tree.py

示例5: add_upper_button

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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) 
开发者ID:sc0tfree,项目名称:mentalist,代码行数:26,代码来源:case.py

示例6: __init__

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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() 
开发者ID:Dogeek,项目名称:rpg-text,代码行数:23,代码来源:map-creator.py

示例7: update_recent_files_menu

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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) 
开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:19,代码来源:Main.py

示例8: create_file_menu

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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) 
开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:24,代码来源:Main.py

示例9: create_file_menu

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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) 
开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:19,代码来源:Main.py

示例10: create_edit_menu

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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) 
开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:26,代码来源:Main.py

示例11: build_menu

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
def build_menu(self):
        menu_bar = tk.Menu(self)
        help_menu = tk.Menu(menu_bar)
        help_menu.add_command(label="在线帮助", command=self.open_online_help)
        help_menu.add_command(label="关于", command=self.show_about)
        help_menu.add_command(label="联系作者/用户群", command=self.contact)
        menu_bar.add_cascade(label="帮助", menu=help_menu)
        self.config(menu=menu_bar) 
开发者ID:winkidney,项目名称:PickTrue,代码行数:10,代码来源:__main__.py

示例12: __init__

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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.requester = Requester()

        self.show_login_screen() 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:18,代码来源:friendslist.py

示例13: __init__

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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() 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:31,代码来源:friendslist.py

示例14: create_python_language_if_needed

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
def create_python_language_if_needed(self):
        if not os.path.exists(self.python_language_path):
            yaml_file_contents = """
categories:
  keywords:
    colour: orange
    matches: [for, def, while, from, import, as, with, self]

  variables:
    colour: red4
    matches: ['True', 'False', None]

  conditionals:
    colour: green
    matches: [try, except, if, else, elif]

  functions:
    colour: blue4
    matches: [int, str, dict, list, set, float]

numbers:
  colour: purple

strings:
  colour: '#e1218b'
"""
            with open(self.python_language_path, 'w') as yaml_file:
                yaml_file.write(yaml_file_contents)







    # =========== Menu Functions ============== 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:38,代码来源:texteditor.py

示例15: onTokenRightClick

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Menu [as 别名]
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() 
开发者ID:jsexauer,项目名称:networkx_viewer,代码行数:35,代码来源:graph_canvas.py


注:本文中的tkinter.Menu方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。