我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用tkinter.ttk.Menubutton()。
def create(self, **kwargs): return ttk.Menubutton(self.root, **kwargs)
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
def add_button(self, text: str = "", menu: tk.Menu = None): button = ttk.Menubutton(self, text=text, menu=menu, direction="above") button.pack(side="left", fill="x", expand=True) return button
def insert_tk_menubutton(self, index: int or str="end", *args, **kwargs): """Insert a tk.Menubutton into the game.""" widget = tk.Menubutton(self.text, **kwargs) self.text.window_create(index, window=widget) return widget
def insert_ttk_menubutton(self, direction: str="below", menu: tk.Menu=None, index: int or str="end", *args, **kwargs): """Insert a ttk.Menubutton into the game.""" widget = ttk.Menubutton(self.text, direction=direction, menu=menu, **kwargs) self.text.window_create(index, window=widget) return widget