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


Python Menu.post方法代码示例

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


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

示例1: Example

# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import post [as 别名]
class Example(Frame):
  
    def __init__(self):
        super().__init__()   
         
        self.initUI()
        
        
    def initUI(self):
      
        self.master.title("Popup menu")
        self.menu = Menu(self.master, tearoff=0)
        self.menu.add_command(label="Beep", command=self.bell)
        self.menu.add_command(label="Exit", command=self.onExit)

        self.master.bind("<Button-3>", self.showMenu)
        self.pack()
        
        
    def showMenu(self, e):
        
        self.menu.post(e.x_root, e.y_root)
       

    def onExit(self):
        
        self.quit()
开发者ID:rinkeigun,项目名称:linux_module,代码行数:29,代码来源:tkpopup.py

示例2: DataEntry

# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import post [as 别名]
class DataEntry(object):

	def __init__(self, parent_frame, grid_col, grid_row, data):

		self._data = data
		self._parent = parent_frame

		self._frame = ttk.Frame(self._parent, borderwidth=2, relief='sunken')
		self._frame.grid(column=grid_col, row=grid_row)

		self._menu = Menu(master=self._parent, tearoff=0)
		self._menu.add_command(label='info', command=self.info_popup)

		self._should_plot = tk.BooleanVar()
		self._should_plot.set(False)

		def menu_popup(event):
			self._menu.post(event.x_root, event.y_root)

		self._chkbox = ttk.Checkbutton(self._frame, text="Plot",
			variable=self._should_plot, onvalue=True)
		self._chkbox.pack()

		self._button = ttk.Button(self._frame,
			text="{} -> {}".format(grid_row, grid_col),
			command=self.info_popup
		)
		self._button.pack()

		self._button.bind('<Button-3>', menu_popup)

	@property
	def data(self):
		return self._data

	@property
	def should_plot(self):
		return self._should_plot.get()

	def info_popup(self):
		top = Toplevel()
		top.title("Info")

		frame = ttk.Frame(top)
		frame.pack()

		sourceLbl = ttk.Label(frame, text="Source")
		targetLbl = ttk.Label(frame, text="Target")

		sourceText = ttk.Label(frame, text=str(self._data._source),
			relief='sunken')
		targetText = ttk.Label(frame, text=str(self._data._target),
			relief='sunken')

		sourceLbl.grid(column=0, row=0)
		targetLbl.grid(column=1, row=0)
		sourceText.grid(column=0, row=1, padx=5, pady=5)
		targetText.grid(column=1, row=1, padx=5, pady=5)
开发者ID:haf,项目名称:cheesepi,代码行数:60,代码来源:data_explorer.py

示例3: click_right

# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import post [as 别名]
 def click_right(self, event):
     menu = Menu(self, tearoff=0)
     try:
         self.selection_get()
         state = 'normal'
     except TclError:
         state = 'disabled'
     menu.add_command(label=_('Copy'), command=self.copy, state=state)
     menu.add_command(label=_('Cut'), command=self.cut, state=state)
     menu.add_command(label=_('Paste'), command=self.paste)
     menu.post(event.x_root, event.y_root)
开发者ID:daleathan,项目名称:getmyancestors,代码行数:13,代码来源:fstogedcom.py

示例4: ShiftReduceApp

# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import post [as 别名]

#.........这里部分代码省略.........
            listscroll.pack(side='left', fill='y')

        # If they select a production, apply it.
        self._prodlist.bind('<<ListboxSelect>>', self._prodlist_select)

        # When they hover over a production, highlight it.
        self._hover = -1
        self._prodlist.bind('<Motion>', self._highlight_hover)
        self._prodlist.bind('<Leave>', self._clear_hover)

    def _init_bindings(self):
        # Quit
        self._top.bind('<Control-q>', self.destroy)
        self._top.bind('<Control-x>', self.destroy)
        self._top.bind('<Alt-q>', self.destroy)
        self._top.bind('<Alt-x>', self.destroy)

        # Ops (step, shift, reduce, undo)
        self._top.bind('<space>', self.step)
        self._top.bind('<s>', self.shift)
        self._top.bind('<Alt-s>', self.shift)
        self._top.bind('<Control-s>', self.shift)
        self._top.bind('<r>', self.reduce)
        self._top.bind('<Alt-r>', self.reduce)
        self._top.bind('<Control-r>', self.reduce)
        self._top.bind('<Delete>', self.reset)
        self._top.bind('<u>', self.undo)
        self._top.bind('<Alt-u>', self.undo)
        self._top.bind('<Control-u>', self.undo)
        self._top.bind('<Control-z>', self.undo)
        self._top.bind('<BackSpace>', self.undo)

        # Misc
        self._top.bind('<Control-p>', self.postscript)
        self._top.bind('<Control-h>', self.help)
        self._top.bind('<F1>', self.help)
        self._top.bind('<Control-g>', self.edit_grammar)
        self._top.bind('<Control-t>', self.edit_sentence)

        # Animation speed control
        self._top.bind('-', lambda e,a=self._animate:a.set(20))
        self._top.bind('=', lambda e,a=self._animate:a.set(10))
        self._top.bind('+', lambda e,a=self._animate:a.set(4))

    def _init_buttons(self, parent):
        # Set up the frames.
        self._buttonframe = buttonframe = Frame(parent)
        buttonframe.pack(fill='none', side='bottom')
        Button(buttonframe, text='Step',
               background='#90c0d0', foreground='black',
               command=self.step,).pack(side='left')
        Button(buttonframe, text='Shift', underline=0,
               background='#90f090', foreground='black',
               command=self.shift).pack(side='left')
        Button(buttonframe, text='Reduce', underline=0,
               background='#90f090', foreground='black',
               command=self.reduce).pack(side='left')
        Button(buttonframe, text='Undo', underline=0,
               background='#f0a0a0', foreground='black',
               command=self.undo).pack(side='left')

    def _init_menubar(self, parent):
        menubar = Menu(parent)

        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label='Reset Parser', underline=0,
开发者ID:52nlp,项目名称:Text-Summarization,代码行数:70,代码来源:srparser_app.py

示例5: MainWindow

# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import post [as 别名]

#.........这里部分代码省略.........

        # Scrollbar widget
        self.scrollbar = ttk.Scrollbar(self.bottom_frame)
        self.scrollbar.grid(column=1, row=1, sticky=N+S+E+W)
        self.list.config(yscrollcommand=self.scrollbar.set)
        self.scrollbar.config(command=self.list.yview)

        self.top_frame.pack(fill=BOTH)
        self.bottom_frame.pack(fill=BOTH)

    def populate_list(self, url_percentage):
        del self.list_of_urls[:]
        for url, percentage in sorted(url_percentage.items(), key=lambda x: x[1]):
            if self.show_all.get() is True:
                row = (str(round(percentage)), url)
                self.list_of_urls.append(row)
            else:
                if percentage >= 1:
                    row = (str(round(percentage)), url)
                    self.list_of_urls.append(row)

        for row in self.list_of_urls:
            self.list.insert('', 0, values=row)


    def on_click(self):
        self.list.delete(*self.list.get_children())
        self.enter.config(text="Running")
        url = self.url.get()
        t = threading.Thread(target=self.run_scan, args=(url,))
        t.start()


    def run_scan(self, url):
        pm = ProcessManager(url)
        pm.start()
        count = 0
        while pm.continue_scanning:
            time.sleep(1)
            count += 1
            # This is to keep the system from reaching a timeout
            if count > 20:
                logging.info("Reached max timeout")
                pm.analyze_potential_urls()
                break

        self.url_dict = pm.url_percentage
        self.populate_list(pm.url_percentage)
        self.enter.config(text="Find Urls")


    def ctrl_c(self, event):
        self.get_selected_url()


    def add_to_clipboard(self, copy):
        self.master.clipboard_clear()
        self.master.clipboard_append(copy)


    def get_from_clipboad(self):
        return self.master.clipboard_get()


    def get_selected_url(self):
        curr_item = self.list.focus()
        item_dict = self.list.item(curr_item)
        self.add_to_clipboard(item_dict['values'][1])


    def paste_to_entry(self):
        self.url.set(self.get_from_clipboad())


    def copy_from_entry(self):
        self.add_to_clipboard(self.url.get())


    def treeview_popup(self, event):
        item = self.list.identify_row(event.y) # Get Row
        self.list.selection_set(item) # Highlight Row
        self.list.focus(item) # Focus Row
        self.right_click.post(event.x_root, event.y_root) # Popup menu


    def entry_popup(self, event):
        self.right_click_entry.post(event.x_root, event.y_root)

    def on_enter(self, event):
        self.on_click()


    def update_list(self):
        self.list.delete(*self.list.get_children())
        self.populate_list(self.url_dict)


    def display_about(self):
        about = "Supporting Url Finder Version: %s" % VERSION
        messagebox.showinfo("About", about)
开发者ID:Just-Sieb,项目名称:Supporting-Url-Finder,代码行数:104,代码来源:gui.py

示例6: popup

# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import post [as 别名]
 def popup(self, event):
     item = self.identify_row(event.y)
     if item:
         menu = Menu(self, tearoff=0)
         menu.add_command(label=_('Remove'), command=self.delete_item(item))
         menu.post(event.x_root, event.y_root)
开发者ID:daleathan,项目名称:getmyancestors,代码行数:8,代码来源:fstogedcom.py

示例7: tableContextMenu

# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import post [as 别名]
 def tableContextMenu(self, event, table=''):
     popup = Menu(self, tearoff=0)
     popup.add_command(label=_("Add Column"), command=lambda cmd='QUERY',query='ADD', table=table: self.onCommand(cmd,query=query,table=table))
     popup.add_command(label=_("Rename Table"), command=lambda cmd='QUERY',query='RENAME', table=table: self.onCommand(cmd,query=query,table=table))
     popup.add_command(label=_("Drop Table"), command=lambda cmd='QUERY',query='DROP', table=table: self.onCommand(cmd,query=query,table=table))
     popup.post(event.x_root, event.y_root)
开发者ID:mncarbone,项目名称:mundiales,代码行数:8,代码来源:dbeditor.py

示例8: SyntaxHighlightingText

# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import post [as 别名]
class SyntaxHighlightingText(ScrolledText2):

    # constructor
    def __init__(self, root, change_hook = None, highlighter = None, grammar=None):
        ScrolledText2.__init__(self,root,change_hook)
        # Non-wrapping, no border, undo turned on, max undo 50
        self.text = self # For the methods taken from IDLE
        self.root = root
        self.change_hook = change_hook
        self.characters = ascii_letters + digits + punctuation
        self.tabwidth = 8    # for IDLE use, must remain 8 until Tk is fixed
        self.indentwidth = 4
        self.indention = 0   # The current indention level
        self.set_tabwidth(self.indentwidth) # IDLE...
        self.previous_line = "0"
        self.highlighter = None

        # create a popup menu
        self.menu = Menu(root, tearoff=0)
        self.menu.add_command(label="Undo", command=self.edit_undo)
        self.menu.add_command(label="Redo", command=self.edit_redo)
        #self.menu.add_command(type="separator")
        self.menu.add_command(label="Cut", command=self.cut)
        self.menu.add_command(label="Copy", command=self.copy)
        self.menu.add_command(label="Paste", command=self.paste)

        self.bind('<KeyRelease>', self.key_release)      # For scanning input
        self.bind('<Return>',self.autoindent)   # Overides default binding
        #self.bind('<Tab>',self.autoindent) # increments self.indention
        #self.bind('<BackSpace>',self.autoindent) # decrements self.indention
        self.bind('<Button-3>', self.popup) # right mouse button opens popup
        self.bind('<Button-1>', self.recolorCurrentLine) # left mouse can reposition cursor, so recolor (e.g. bracket highlighting necessary)
        self.bind('<Control-Any-KeyPress>', self.ctrl)
        
        self.grammar = grammar
        
        self.setHighlighter(highlighter)

    def setHighlighter(self, highlighter):
        if highlighter is None:
            highlighter = Highlighter()
        self.highlighter = highlighter
        # sets up the tags
        for tag, settings in list(self.highlighter.tags.items()):
            self.tag_config(tag, **settings)

    def popup(self, event):
        self.menu.post(event.x_root, event.y_root)

    def get_tabwidth(self):
        # From IDLE
        current = self['tabs'] or 5000
        return int(current)

    def set_tabwidth(self, newtabwidth):
        # From IDLE
        text = self
        if self.get_tabwidth() != newtabwidth:
            pixels = text.tk.call("font", "measure", text["font"],
                                  "-displayof", text.master,
                                  "n" * newtabwidth)
            text.configure(tabs=pixels)

    def remove_singleline_tags(self, start, end):
        for tag in list(self.highlighter.tags.keys()):
            if tag[:2] != 'ml':
                self.tag_remove(tag, start, end)

    def get_selection_indices(self):
        # If a selection is defined in the text widget, return (start,
        # end) as Tkinter text indices, otherwise return (None, None)
        try:
            first = self.text.index("sel.first")
            last = self.text.index("sel.last")
            return first, last
        except TclError:
            return None

    # Select all the text in textbox
    def select_all(self):
        self.tag_add(SEL, "1.0", END)
        self.mark_set(INSERT, END)
        self.see(INSERT)
        self.focus_set()
        return 'break'

    def cut(self, event=0):
        self.clipboard_clear()
        Selection=self.get_selection_indices()
        if Selection is not None:
            SelectedText = self.get(Selection[0],Selection[1])
            self.delete(Selection[0],Selection[1])
            self.clipboard_append(SelectedText)
            self.onChange()

    def copy(self, event=0):
        self.clipboard_clear()
        Selection=self.get_selection_indices()
        if Selection is not None:
            SelectedText = self.get(Selection[0],Selection[1])
#.........这里部分代码省略.........
开发者ID:bbferka,项目名称:pracmln,代码行数:103,代码来源:widgets.py

示例9: WorkingFrame

# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import post [as 别名]
class WorkingFrame(Frame):
    
    def __init__(self, master, restore_project=False, **kw):
        Frame.__init__(self, master, **kw)
        
        #Load a project
        if restore_project:
            self.project = templify.Project.load(filedialog.askopenfilename())
        else:
            self.project = templify.Project(sample_file=filedialog.askopenfilename())
                    
        #Text
        self.text = Text(self)
        self.init_text()
        
        #Scrollbars
        self.vertical_scrollbar = ttk.Scrollbar(self)
        self.horizontal_scrollbar = ttk.Scrollbar(self)
        self.init_scrollbars()
        
        #Pop-up menu
        self.pop_up_menu = Menu(self)
        self.init_pop_up_menu()
        
        #Layout management        
        self.grid_conf()
        
        #Binding management
        self.master.bind('<Control-s>', lambda e:self.project.save())
        self.master.bind('<3>', lambda e: self.pop_up_menu.post(e.x_root, e.y_root))
    
    def grid_conf(self):
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)
        
        self.vertical_scrollbar.grid(column=1, row=0, sticky='ns')
        self.horizontal_scrollbar.grid(column=0, row=1, sticky='ew')
    
    def init_scrollbars(self):
        self.vertical_scrollbar.configure(orient=tk.VERTICAL, command=self.text.yview)
        self.text.configure(yscrollcommand=self.vertical_scrollbar.set)
        self.horizontal_scrollbar.configure(orient=tk.HORIZONTAL, command=self.text.xview)
        self.text.configure(xscrollcommand=self.horizontal_scrollbar.set)
    
    def init_text(self):
        text = self.text

        for line in self.project.sample_content:
            text.insert('end', line)
            
        text.configure(wrap='none', state='disabled')
        self.text.grid(row=0, column=0, sticky="nesw")
    
    def init_pop_up_menu(self):
        pop_up_commands = [('templify selection', self.templify_selection),
                           ]
        for label, command in pop_up_commands:
            self.pop_up_menu.add_command(label=label, command=command)
            
    def templify_selection(self):
        
        start, end = [templify.Position(*index.string.split('.')) for index in self.text.tag_ranges('sel')]
        selection = self.text.selection_get()
        context_line = self.text.get('%s.0' % start.line, '%s.end' % start.line)
        
        log.debug('Start: %s, End: %s' % (start, end))
        log.debug('Content: %s' % self.text.selection_get())
        log.debug('Context: %s' % self.text.get('%s.0' % start.line, '%s.end' % start.line))
        
        guessed_snippet = templify.FieldSnippet.guess_snippet(start, end, selection, context_line)
        NewSnippetDialog(self.master, initial_snippet=guessed_snippet)
开发者ID:NicoBernard,项目名称:templify,代码行数:73,代码来源:templify_ui.py


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