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 vote down vote up
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: friendslist.py    From Tkinter-GUI-Programming-by-Example with MIT License 6 votes vote down vote up
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 #3
Source File: texteditor.py    From Tkinter-GUI-Programming-by-Example with MIT License 6 votes vote down vote up
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 #4
Source File: texteditor.py    From Tkinter-GUI-Programming-by-Example with MIT License 6 votes vote down vote up
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 #5
Source File: viewer.py    From networkx_viewer with GNU General Public License v3.0 6 votes vote down vote up
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 #6
Source File: tree.py    From razzy-spinner with GNU General Public License v3.0 6 votes vote down vote up
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: case.py    From mentalist with MIT License 6 votes vote down vote up
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 #8
Source File: map-creator.py    From rpg-text with MIT License 6 votes vote down vote up
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 #9
Source File: Main.py    From python-in-practice with GNU General Public License v3.0 6 votes vote down vote up
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 #10
Source File: Main.py    From python-in-practice with GNU General Public License v3.0 6 votes vote down vote up
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 #11
Source File: Main.py    From python-in-practice with GNU General Public License v3.0 6 votes vote down vote up
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 #12
Source File: Main.py    From python-in-practice with GNU General Public License v3.0 6 votes vote down vote up
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 #13
Source File: __main__.py    From PickTrue with MIT License 5 votes vote down vote up
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) 
Example #14
Source File: friendslist.py    From Tkinter-GUI-Programming-by-Example with MIT License 5 votes vote down vote up
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() 
Example #15
Source File: texteditor.py    From Tkinter-GUI-Programming-by-Example with MIT License 5 votes vote down vote up
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 ============== 
Example #16
Source File: graph_canvas.py    From networkx_viewer with GNU General Public License v3.0 5 votes vote down vote up
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 #17
Source File: graph_canvas.py    From networkx_viewer with GNU General Public License v3.0 5 votes vote down vote up
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 #18
Source File: chartparser_app.py    From razzy-spinner with GNU General Public License v3.0 5 votes vote down vote up
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: chartparser_app.py    From razzy-spinner with GNU General Public License v3.0 5 votes vote down vote up
def about(self, *e):
        ABOUT = ("NLTK Chart Parser Application\n"+
                 "Written by Edward Loper")
        tkinter.messagebox.showinfo('About: Chart Parser Application', ABOUT)

    #////////////////////////////////////////////////////////////
    # File Menu
    #//////////////////////////////////////////////////////////// 
Example #20
Source File: chartparser_app.py    From razzy-spinner with GNU General Public License v3.0 5 votes vote down vote up
def set_sentence(self, sentence):
        self._tokens = list(sentence.split())
        self.reset()

    #////////////////////////////////////////////////////////////
    # View Menu
    #//////////////////////////////////////////////////////////// 
Example #21
Source File: chartparser_app.py    From razzy-spinner with GNU General Public License v3.0 5 votes vote down vote up
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 #22
Source File: base_words.py    From mentalist with MIT License 5 votes vote down vote up
def add_file_menu(self, menu_button, menu):
        '''Adds items representing the built-in files to the given menu_button
        and menu
        '''
        for label, value in model.FileAttr.named_files:
            if isinstance(value, str):
                menu.add_command(label=label, command=partial(self.controller.add_attr, label=label, right_label_text='Calculating...', node_view=self, attr_class=model.FileAttr, path=value, controller=self.controller))
            else:
                submenu = Tk.Menu(menu_button, tearoff=0)
                menu.add_cascade(label=label, menu=submenu, underline=0)
                
                for sublabel, subvalue in value:
                    submenu.add_command(label=sublabel, command=partial(self.controller.add_attr, label='%s: %s' % (label, sublabel), right_label_text='Calculating...', node_view=self, attr_class=model.FileAttr, path=subvalue, controller=self.controller)) 
Example #23
Source File: base_words.py    From mentalist with MIT License 5 votes vote down vote up
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 Words'
        mb.menu.add_command(label=label, command=partial(self.controller.add_attr, label=label, node_view=self, attr_class=model.NothingAdderAttr))
        
        mb.menu.add_command(label="Custom File...", command=partial(self.open_file_dlg, partial(self.controller.add_attr, label='File:', right_label_text='Calculating...', node_view=self, attr_class=model.FileAttr, controller=self.controller)))
        
        mb.menu.add_command(label="Custom String...", command=partial(self.open_string_popup, 'String'))
        
        self.add_file_menu(mb, mb.menu)
        
        mb.pack(side="left", fill="x", padx=10, pady=5) 
Example #24
Source File: substitution.py    From mentalist with MIT License 5 votes vote down vote up
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 Substitution'
        mb.menu.add_command(label=label, command=partial(self.controller.add_attr, label=label, node_view=self, attr_class=model.NothingMutatorAttr))
        mb.menu.add_command(label='Replace All Instances...', command=partial(self.open_sub_popup, 'All'))
        mb.menu.add_command(label='Replace First Instance...', command=partial(self.open_sub_popup, 'First'))
        mb.menu.add_command(label='Replace Last Instance...', command=partial(self.open_sub_popup, 'Last'))

        mb.pack(side='left', fill='x', padx=10, pady=5) 
Example #25
Source File: mainWindow.py    From PyEveLiveDPS with GNU General Public License v3.0 5 votes vote down vote up
def addMenus(self):
        # character menu options are added dynamically by CharacterDetector, so we pass this into that
        self.characterMenu = tk.Menubutton(text="Character...", background="black", fg="white", borderwidth="1",
                                      highlightbackground="black", highlightthickness="1",
                                      activebackground="gray25", activeforeground="white")
        self.characterMenu.grid(row="5", column="2")
        self.characterMenu.menu = tk.Menu(self.characterMenu, tearoff=False)
        self.characterMenu["menu"] = self.characterMenu.menu
        self.characterDetector = logreader.CharacterDetector(self, self.characterMenu)
        
        # Set up file menu options
        self.mainMenu = tk.Menubutton(text="File...", background="black", fg="white", borderwidth="1",
                                      highlightbackground="black", highlightthickness="1",
                                      activebackground="gray25", activeforeground="white")
        self.mainMenu.grid(row="5", column="1")
        self.mainMenu.menu = tk.Menu(self.mainMenu, tearoff=False)
        self.mainMenu["menu"] = self.mainMenu.menu
        self.mainMenu.menu.add_command(label="Edit Profile Settings", command=lambda: settingsWindow.SettingsWindow(self))
        
        # add all the profiles from settings into the menu
        self.profileMenu = tk.Menu(self.mainMenu, tearoff=False)
        settings.initializeMenu(self)
        
        self.mainMenu.menu.add_cascade(label="Profile", menu=self.profileMenu)
        self.mainMenu.menu.add_separator()
        self.mainMenu.menu.add_command(label="Clear Total/Peak Values", state=tk.DISABLED)
        self.mainMenu.menu.add_separator()
        self.mainMenu.menu.add_command(label="Fleet Mode", command=lambda: fleetConnectionWindow.FleetWindow(self))
        self.mainMenu.menu.add_separator()
        self.mainMenu.menu.add_command(label="Simulate Input", command=lambda: simulationWindow.SimulationWindow(self))
        getLogFilePath = lambda: tk.filedialog.askopenfilename(initialdir=self.characterDetector.path, title="Select log file")
        self.mainMenu.menu.add_command(label="Playback Log", command=lambda: self.characterDetector.playbackLog(getLogFilePath()))
        self.mainMenu.menu.add_separator()
        self.mainMenu.menu.add_command(label="Quit", command=self.quitEvent) 
Example #26
Source File: Main.py    From python-in-practice with GNU General Public License v3.0 5 votes vote down vote up
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_view_menu()
        self.create_window_menu()
        self.create_help_menu() 
Example #27
Source File: Main.py    From python-in-practice with GNU General Public License v3.0 5 votes vote down vote up
def create_file_menu(self):
        modifier = TkUtil.menu_modifier()
        self.fileMenu = tk.Menu(self.menubar, name="apple")
        self.fileMenu.add_command(label=NEW, underline=0,
                command=self.new, image=self.menuImages[NEW],
                compound=tk.LEFT, accelerator=modifier + "+N")
        self.fileMenu.add_command(label=OPEN + ELLIPSIS, underline=0,
                command=self.open, image=self.menuImages[OPEN],
                compound=tk.LEFT, accelerator=modifier + "+O")
        self.fileMenu.add_cascade(label=OPEN_RECENT,
                underline=5, image=self.menuImages[OPEN],
                compound=tk.LEFT)
        self.fileMenu.add_command(label=SAVE, underline=0,
                command=self.save, image=self.menuImages[SAVE],
                compound=tk.LEFT, accelerator=modifier + "+S")
        self.fileMenu.add_command(label=SAVE_AS + ELLIPSIS, underline=5,
                command=self.save_as, image=self.menuImages[SAVEAS],
                compound=tk.LEFT)
        if TkUtil.mac():
            self.master.createcommand("::tk::mac::ShowPreferences",
                    self.preferences)
            self.master.createcommand("exit", self.close)
        else:
            self.fileMenu.add_separator()
            self.fileMenu.add_command(label=PREFERENCES + ELLIPSIS,
                    underline=0, image=self.menuImages[PREFERENCES],
                    compound=tk.LEFT, command=self.preferences)
            self.fileMenu.add_separator()
            self.fileMenu.add_command(label=QUIT, underline=0,
                    command=self.close, compound=tk.LEFT,
                    image=self.menuImages[QUIT],
                    accelerator=modifier + "+Q")
        self.menubar.add_cascade(label="File", underline=0,
                menu=self.fileMenu)


    # NOTE: the Tkinter API doesn't seem to let us check whether redo is
    # possible (so here we always leave Redo enabled). 
Example #28
Source File: Main.py    From python-in-practice with GNU General Public License v3.0 5 votes vote down vote up
def create_edit_menu(self):
        modifier = TkUtil.menu_modifier()
        self.editMenu = tk.Menu(self.menubar)
        self.editMenu.add_command(label=UNDO, underline=0,
                command=self.editor.edit_undo,
                image=self.menuImages[UNDO], compound=tk.LEFT,
                accelerator=modifier + "+Z")
        redo = "+Shift+Z"
        if TkUtil.windows():
            redo = "+Y"
        self.editMenu.add_command(label=REDO, underline=0,
                command=self.editor.edit_redo,
                image=self.menuImages[REDO], compound=tk.LEFT,
                accelerator=modifier + redo)
        self.editMenu.add_separator()
        self.editMenu.add_command(label=COPY, underline=0,
                command=lambda: self.editor.text.event_generate(
                    "<<Copy>>"), image=self.menuImages[COPY],
                compound=tk.LEFT, accelerator=modifier + "+C")
        self.editMenu.add_command(label=CUT, underline=2,
                command=lambda: self.editor.text.event_generate("<<Cut>>"),
                image=self.menuImages[CUT], compound=tk.LEFT,
                accelerator=modifier + "+X")
        self.editMenu.add_command(label=PASTE, underline=0,
                command=lambda: self.editor.text.event_generate(
                    "<<Paste>>"), image=self.menuImages[PASTE],
                compound=tk.LEFT, accelerator=modifier + "+V")
        self.editMenu.add_separator()
        self.editMenu.add_command(label=FIND + ELLIPSIS, underline=0,
                command=self.find, image=self.menuImages[FIND],
                compound=tk.LEFT, accelerator=modifier + "+F")
        self.menubar.add_cascade(label="Edit", underline=0,
                menu=self.editMenu)


    # Tcl/Tk 8.6 provides access to the native font chooser dialog 
Example #29
Source File: Main.py    From python-in-practice with GNU General Public License v3.0 5 votes vote down vote up
def create_view_menu(self):
        modifier = TkUtil.menu_modifier()
        viewMenu = tk.Menu(self.menubar)
        viewMenu.add_checkbutton(label=BOLD, underline=0,
                image=self.menuImages[BOLD], compound=tk.LEFT,
                variable=self.bold,
                command=lambda: self.toggle_button(self.boldButton))
        viewMenu.add_checkbutton(label=ITALIC, underline=0,
                image=self.menuImages[ITALIC], compound=tk.LEFT,
                variable=self.italic,
                command=lambda: self.toggle_button(self.italicButton))
        viewMenu.add_separator()
        viewMenu.add_radiobutton(label=ALIGN_LEFT, underline=6,
                image=self.menuImages[ALIGNLEFT], compound=tk.LEFT,
                variable=self.alignment, value=tk.LEFT,
                command=self.toggle_alignment)
        viewMenu.add_radiobutton(label=ALIGN_CENTER, underline=6,
                image=self.menuImages[ALIGNCENTER],
                compound=tk.LEFT, variable=self.alignment, value=tk.CENTER,
                command=self.toggle_alignment)
        viewMenu.add_radiobutton(label=ALIGN_RIGHT, underline=6,
                image=self.menuImages[ALIGNRIGHT],
                compound=tk.LEFT, variable=self.alignment, value=tk.RIGHT,
                command=self.toggle_alignment)
        self.menubar.add_cascade(label="View", underline=0,
                menu=viewMenu) 
Example #30
Source File: Main.py    From python-in-practice with GNU General Public License v3.0 5 votes vote down vote up
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.menubar.add_cascade(label="Window", underline=0,
                menu=self.windowMenu)