def make_file_type_menu(self, menubar): _, e = os.path.splitext(self.file) ext = e[1:] if ext == "py": pybtn = Menubutton(menubar, text='Python', name=ext) pybtn.pack(side=LEFT) py = Menu(pybtn, tearoff=0) py.add_command(label='Compile', command=self.compile_python, accelerator="Ctrl+F5") py.add_command(label='Run', command=self.run_python, accelerator="F5") pybtn.config(menu=py) self.bind_all("<Control-F5>", self.compile_python) self.bind_all("<F5>", self.run_python) elif ext == "tcl": tclbtn = Menubutton(menubar, text='TCL', name=ext) tclbtn.pack(side=LEFT) tcl = Menu(tclbtn, tearoff=0) tcl.add_command(label='Run', command=self.run_tcl, accelerator="F5") tclbtn.config(menu=tcl) self.bind_all("<F5>", self.run_tcl)
def makemenu(parent): ''' Builds the menu :param parent: the parent component ''' menubar = Frame(parent) # relief=RAISED, bd=2... menubar.pack(side=TOP, fill=X) fbutton = Menubutton(menubar, text='File', underline=0) fbutton.pack(side=LEFT) file = Menu(fbutton) file.add_command(label='New...', command=notdone, underline=0) file.add_command(label='Open...', command=notdone, underline=0) file.add_command(label='Quit', command=parent.quit, underline=0) fbutton.config(menu=file) ebutton = Menubutton(menubar, text='Edit', underline=0) ebutton.pack(side=LEFT) edit = Menu(ebutton, tearoff=False) edit.add_command(label='Cut', command=notdone, underline=0) edit.add_command(label='Paste', command=notdone, underline=0) edit.add_separator() ebutton.config(menu=edit) submenu = Menu(edit, tearoff=True) submenu.add_command(label='Spam', command=parent.quit, underline=0) submenu.add_command(label='Eggs', command=notdone, underline=0) edit.add_cascade(label='Stuff', menu=submenu, underline=0) return menubar
class PairMenu(PairSelector): def __init__(self, parent: Widget, chart_manager, color): PairSelector.__init__(self, parent, chart_manager, color) self.pair_var = StringVar() self.menubutton = Menubutton( self, textvariable=self.pair_var, font=Fonts.FIXED_14, width=7, background=color, foreground=color.contrast, bd=0, pady=6, ) self.menu = Menu( self.menubutton, background=color, foreground=color.contrast, font=Fonts.FIXED_14, tearoff=False, ) self.menubutton["menu"] = self.menu for pair in Pair.iter_pairs(): self.menu.add_command(label=pair.camel(), command=partial(self.pair_callback, pair)) if pair in self.SEPARATOR_AFTER: self.menu.add_separator() grid(self.menubutton, 0, 0) def set_pair(self, pair: Optional[Pair]): if pair is None: self.pair_var.set("pair") self.menubutton.config(foreground="grey") else: self.pair_var.set(pair.camel()) self.menubutton.config(foreground=self.color.contrast) def pair_callback(self, pair: Pair): self.apply_pair(pair) SEPARATOR_AFTER = { Pair.EUR_JPY, Pair.GBP_JPY, Pair.AUD_JPY, Pair.NZD_JPY, Pair.USD_JPY, Pair.CAD_JPY, }
class QuoteKindMenu(QuoteKindSelector): def __init__(self, parent: Widget, chart_manager, color): QuoteKindSelector.__init__(self, parent, chart_manager, color) self.quote_kind_var = StringVar() self.menubutton = Menubutton( self, textvariable=self.quote_kind_var, font=Fonts.FIXED_14, width=4, background=color, foreground=color.contrast, bd=0, pady=6, ) self.menu = Menu( self.menubutton, background=color, foreground=color.contrast, font=Fonts.FIXED_14, tearoff=False, ) self.menubutton["menu"] = self.menu self.menu.add_command( label=QuoteKind.ASK.name, command=partial(self.quote_kind_callback, QuoteKind.ASK), ) self.menu.add_command( label=QuoteKind.MID.name, command=partial(self.quote_kind_callback, QuoteKind.MID), ) self.menu.add_command( label=QuoteKind.BID.name, command=partial(self.quote_kind_callback, QuoteKind.BID), ) grid(self.menubutton, 0, 0) def set_quote_kind(self, quote_kind: Optional[QuoteKind]): if not quote_kind: self.quote_kind_var.set("amb") self.menubutton.config(foreground="grey") else: self.quote_kind_var.set(quote_kind) self.menubutton.config(foreground=self.color.contrast) def quote_kind_callback(self, quote_kind: QuoteKind): self.apply_quote_kind(quote_kind)
def _make_menu_bar(self): """ make menu bar at the top (TK9.0 menus below) expand=no, fill=X so same width on resize """ menu_bar = Frame(self, relief=RAISED, bd=2) menu_bar.pack(side=TOP, fill=X) for (name, key, items) in self.menu_bar: mbutton = Menubutton(menu_bar, text=name, underline=key) mbutton.pack(side=LEFT) pulldown = Menu(mbutton) self._add_menu_items(pulldown, items) mbutton.config(menu=pulldown) if self.help_button: Button(menu_bar, text='Help', cursor='gumby', relief=FLAT, command=self.help).pack(side=RIGHT)
def make_menu(self): self.menubar = Frame(self) self.menubar.pack(side=TOP) filebtn = Menubutton(self.menubar, text='File') filebtn.pack(side=LEFT) file = Menu(filebtn, tearoff=0) file.add_command(label='New', command=self.new, accelerator="Ctrl+N") file.add_command(label='Save', command=self.save, accelerator="Ctrl+S") file.add_command(label='Quit', command=self.quit, accelerator="Ctrl+Q") filebtn.config(menu=file) editbtn = Menubutton(self.menubar, text='Edit') editbtn.pack(side=LEFT) edit = Menu(editbtn, tearoff=0) edit.add_command(label='Cut', command=self.cut) edit.add_command(label='Copy', command=self.copy) edit.add_command(label='Paste', command=self.paste) editbtn.config(menu=edit) if self.file: self.make_file_type_menu(self.menubar)
""" Menubutton example """ from tkinter import Tk, Menubutton, Menu from tkinter import RAISED root = Tk() mbutton = Menubutton(root, text='Food') # the pull-down stands alone picks = Menu(mbutton) mbutton.config(menu=picks) picks.add_command(label='spam', command=root.quit) picks.add_command(label='eggs', command=root.quit) picks.add_command(label='bacon', command=root.quit) mbutton.pack() mbutton.config(bg='white', bd=4, relief=RAISED) root.mainloop()
def boldDoc(): global textarea textarea.config(font=('arial', 14, 'bold')) root = Tk() root.title("MicroService") savebtn = Button( root, command=saveDoc, text="Save", ) savebtn.grid(row=1, column=0) savebtn.config(font=('cursive', 16, 'bold'), bg="Hotpink", fg="white") fontbtn = Menubutton(root, text="Font") fontbtn.config(font=('arial', 16, 'bold'), bg="#00FFFF", fg="white") fontbtn.grid(row=1, column=1) fontbtn.menu = Menu(fontbtn, tearoff=0) fontbtn["menu"] = fontbtn.menu fontbtn.menu.add_checkbutton(label="Arial", command=Arial) fontbtn.menu.add_checkbutton(label="Algerian", command=Algerian) fontbtn.menu.add_checkbutton(label="Cambria", command=Cambria) fontbtn.menu.add_checkbutton(label="Courier", command=Courier) boldbtn = Button(root, command=boldDoc, text="Bold") boldbtn.grid(row=1, column=2) boldbtn.config(font=('arial', 16, 'bold'), bg="#8B0000", fg="white") textarea = Text(root) textarea.grid(row=2, columnspan=5) root.mainloop()
class Roller(Frame): def __init__(self, group, index): Frame.__init__(self, group) self.group = group self.index = index self.results = [0] self.history = [] self.name = StringVar() self.dice_qty = IntVar() self.die_faces = IntVar() self.modifier = IntVar() self.finalmod = IntVar() self.results_text = StringVar() self.name.trace('w', self.group.mainframe.set_unsaved_title) self.dice_qty.trace('w', self.group.mainframe.set_unsaved_title) self.die_faces.trace('w', self.group.mainframe.set_unsaved_title) self.modifier.trace('w', self.group.mainframe.set_unsaved_title) self.finalmod.trace('w', self.group.mainframe.set_unsaved_title) self.results_text.trace('w', self.group.mainframe.set_unsaved_title) default_font = ('Courier', 14) self.menu_btn = Menubutton(self, bd=1, relief='solid', font=('Courier', 8), text='\u25e2', takefocus=1, highlightthickness=1) self.name_entry = Entry(self, bd=1, relief='solid', font=('Verdana', 12), width=16, textvariable=self.name) self.dice_qty_spin = NumericSpinner(self, self.dice_qty, 1, 99, callback=self.reset, initial=1) self.die_faces_spin = NumericSpinner( self, self.die_faces, 2, 100, interval=self.group.mainframe.allow_odd.get(), initial=10) self.modifier_spin = NumericSpinner(self, self.modifier, -99, 100, callback=self.apply_modifiers) self.finalmod_spin = NumericSpinner(self, self.finalmod, -99, 100, callback=self.apply_modifiers) self.dice_lbl = Label(self, text=' d', font=default_font) self.modifier_lbl = Label(self, text='\u002b', font=default_font) self.finalmod_lbl = Label(self, text='\u002b', font=default_font) self.roll_btn = Button(self, bd=0, image=self.group.roll_img, command=lambda: self.roll(single=True)) self.results_entry = Entry(self, bd=0, relief='solid', font=default_font, width=0, textvariable=self.results_text, state='readonly', justify='center') self.menu_btn.config(menu=self.create_menu()) self.menu_btn.grid(row=index, column=0, padx=(4, 0)) self.name_entry.grid(row=index, column=1, padx=(4, 0)) self.dice_qty_spin.grid(row=index, column=2, padx=(4, 0)) self.dice_lbl.grid(row=index, column=3, padx=(0, 0)) self.die_faces_spin.grid(row=index, column=4, padx=(0, 0)) self.modifier_lbl.grid(row=index, column=5, padx=(6, 6)) self.modifier_spin.grid(row=index, column=6, padx=(0, 0)) self.roll_btn.grid(row=index, column=7, padx=(8, 0)) self.results_entry.grid(row=index, column=8, padx=(8, 0)) self.finalmod_lbl.grid(row=index, column=9, padx=(6, 6)) self.finalmod_spin.grid(row=index, column=10, padx=(0, 4)) self.name.set('Roller {}'.format(len(self.group.rollers) + 1)) self.die_faces.set(10) self.results_text.set('0 = 0') self.grid(row=index, sticky='w', pady=4) def create_menu(self): menu = Menu(self.menu_btn, tearoff=0, postcommand=self.group.maintain_roller_indices) menu.add_command(label='Add', underline=0, command=self.add_roller) menu.add_command(label='Clone', underline=0, command=lambda: self.add_roller(clone=True)) menu.add_command(label='Up', underline=0, command=lambda: self.move_roller(offset=-1)) menu.add_command(label='Down', underline=0, command=lambda: self.move_roller(offset=1)) menu.add_separator() # ------ menu.add_command(label='Remove', underline=0, command=self.remove_roller) return menu def create_hist_record(self): record = { 'dice_qty': self.dice_qty.get(), 'die_faces': self.die_faces.get(), 'modifier': self.modifier.get(), 'results_text': self.results_text.get(), 'finalmod': self.finalmod.get(), 'timestamp': str(dt.now().time())[:8], 'results': self.results } return record def add_roller(self, clone=False): destination_index = self.index + 1 roller = Roller(self.group, destination_index) self.group.rollers.insert(roller.index, roller) for i in range(destination_index, len(self.group.rollers)): self.group.rollers[i].grid(row=i + 1) if clone: roller.name.set(self.name.get()) roller.dice_qty.set(self.dice_qty.get()) roller.die_faces.set(self.die_faces.get()) roller.modifier.set(self.modifier.get()) roller.finalmod.set(self.finalmod.get()) roller.reset() for h in self.history: record = roller.create_hist_record() record['timestamp'] = h['timestamp'] roller.history.append(record) roller.apply_modifiers() for r in self.group.rollers: r.lift() self.group.mainframe.editmenu.entryconfigure( self.group.mainframe.editmenu.index('end'), command=lambda: self.add_roller(clone=clone)) self.group.mainframe.bind_all('<Control-r>', lambda e: self.add_roller(clone=clone)) def move_roller(self, offset=0, destination_index=0): if not destination_index: destination_index = self.index + offset if destination_index >= 0: roller = self.group.rollers.pop(self.index) self.group.rollers.insert(destination_index, roller) self.group.maintain_roller_indices() self.name.set(self.name.get()) self.group.mainframe.editmenu.entryconfigure( self.group.mainframe.editmenu.index('end'), command=lambda: self.move_roller(offset=offset)) self.group.mainframe.bind_all( '<Control-r>', lambda e: self.move_roller(offset=offset)) def remove_roller(self): if len(self.group.rollers) > 1: self.grid_remove() self.group.rollers.remove(self) self.name.set('') def reset(self, loading=False): self.results = [0 for i in range(self.dice_qty.get())] self.dice_qty_spin.step(0) self.die_faces_spin.step(0) self.modifier_spin.step(0) self.finalmod_spin.step(0) if not loading: self.apply_modifiers() self.group.maintain_result_widths() def roll(self, single=False): rolls = self.dice_qty.get() sides = self.die_faces.get() if self.group.mainframe.allow_odd.get() % 2 == 0 and sides % 2 != 0: self.die_faces.set(sides - 1) sides -= 1 mod = self.modifier.get() fmod = self.finalmod.get() max_roll = sides min_roll = 1 results = [] if self.group.mainframe.use_random_org.get(): url = 'https://www.random.org/integers/?col={0}&num={0}&min={1}&max={2}&base=10&format=plain&rnd=new' url = url.format(rolls, min_roll, max_roll) try: resp = urlopen(url) results.extend([ int(x) for x in str(resp.read().rstrip(), encoding='utf8').split('\t') ]) sleep(0.1) except: print('Failed to use random.org, falling back to CSPRNG!') if not results: csprng = SystemRandom() for i in range(rolls): roll = csprng.randint(min_roll, sides) results.append(roll) self.results = [] for n in results: if n == max_roll: self.results.append(n * CRIT) elif n == min_roll: self.results.append(n * FAIL) else: self.results.append(n) self.apply_modifiers(True) self.history.append(self.create_hist_record()) hist_index = len(self.history) - 1 if single: for roller in self.group.rollers: if roller is not self: roller.history.append(roller.create_hist_record()) self.group.navigate_history(desired_index=hist_index) self.group.hist_index = hist_index self.name.set(self.name.get()) self.group.mainframe.editmenu.entryconfigure( self.group.mainframe.editmenu.index('end'), command=lambda: self.roll(single=single)) self.group.mainframe.bind_all('<Control-r>', lambda e: self.roll(single=single)) def apply_modifiers(self, rolling=False): fmod = self.finalmod.get() dmod = self.modifier.get() dqty = self.dice_qty.get() formatted_results = [] total = 0 for n in self.results: if n > CRIT: n = int(n / CRIT) n = n + dmod formatted_results.append('\u25b2{}'.format(str(n))) elif 0 < n < 1: n = int(n / FAIL) n = n + dmod formatted_results.append('\u25bc{}'.format(str(n))) else: n = n + dmod formatted_results.append(str(n)) total += n s = ' + '.join(formatted_results) s = '{} = {}'.format(total + fmod, s) if not rolling and self.history: self.history[self.group.hist_index]['modifier'] = dmod self.history[self.group.hist_index]['finalmod'] = fmod self.history[self.group.hist_index]['results_text'] = s self.results_text.set(s) self.group.maintain_result_widths()
class RollerGroup(LabelFrame): def __init__(self, mainframe, index): LabelFrame.__init__(self, mainframe) self.mainframe = mainframe self.index = index self.hist_index = 0 self.collapsed = False self.rollers = [] self.control_frame = Frame(None) default_font = ('Verdana', 10) self.name = StringVar() self.name.trace('w', self.mainframe.set_unsaved_title) self.expand_img = PhotoImage( data= b'R0lGODlhEAAQAIABAAAAAP///yH5BAEKAAEALAAAAAAQABAAAAIlhI+pq+EPHYo0TGjifRkfDYAdI33WUnZc6KmlyK5wNdMrg+dJAQA7' ) self.collapse_img = PhotoImage( data= b'R0lGODlhEAAQAIABAAAAAP///yH5BAEKAAEALAAAAAAQABAAAAIfhI+pq+EPHYo0zAovlme/y3CGmJCeeWqbirEVA8dLAQA7' ) self.collapse_btn = Button(self.control_frame, bd=0, image=self.collapse_img, command=self.show_hide) self.menu_btn = Menubutton(self.control_frame, bd=1, relief='solid', font=('Courier', 8), text='\u25e2', takefocus=1, highlightthickness=1) self.name_entry = Entry(self.control_frame, bd=1, relief='solid', font=('Verdana', 12), width=16, textvariable=self.name) self.history_frame = LabelFrame(self.control_frame, bd=1, text='History', relief='solid', font=default_font, labelanchor='w') self.roll_frame = LabelFrame(self.control_frame, bd=1, text='Roll', relief='solid', font=default_font, labelanchor='w') self.roll_img = PhotoImage( data= b'R0lGODlhDgARAIABAAAAAP///yH5BAEKAAEALAAAAAAOABEAAAIkjB+Ai6C83GOy0iqjM7ltPoFhKEKeKZJadynfVa6HlbAp3ZIFADs=' ) self.left_arrow = PhotoImage( data= b'R0lGODlhBwANAIABAAAAAP///yH5BAEKAAEALAAAAAAHAA0AAAITjA9nkMj+Apty2lvt0jt2VYFSAQA7' ) self.right_arrow = PhotoImage( data= b'R0lGODlhBwANAIABAAAAAP///yH5BAEKAAEALAAAAAAHAA0AAAITRI5gGLrnXlzT1NsidEkx/zFHAQA7' ) self.roll_btn = Button(self.roll_frame, bd=0, image=self.roll_img, height=24, command=self.roll_group) self.hist_prev_btn = Button( self.history_frame, bd=0, image=self.left_arrow, height=24, width=16, repeatdelay=250, repeatinterval=100, command=lambda: self.navigate_history(offset=-1)) self.hist_next_btn = Button( self.history_frame, bd=0, image=self.right_arrow, height=24, width=16, repeatdelay=250, repeatinterval=100, command=lambda: self.navigate_history(offset=1)) self.menu_btn.config(menu=self.create_menu()) self.collapse_btn.grid(row=0, column=0, padx=(4, 0)) self.menu_btn.grid(row=0, column=1, padx=(4, 0)) self.name_entry.grid(row=0, column=2, padx=(4, 0)) self.history_frame.grid(row=0, column=3, padx=(6, 0)) self.hist_prev_btn.grid(row=0, column=0, padx=(6, 0)) self.hist_next_btn.grid(row=0, column=1, padx=(0, 2)) self.roll_frame.grid(row=0, column=4, padx=(6, 4)) self.roll_btn.grid(row=0, column=0, padx=(6, 2)) self.config(relief='solid', labelwidget=self.control_frame) self.name.set('Group {}'.format(len(roller_groups) + 1)) self.grid(row=index, padx=4, pady=4, sticky='w') def show_hide(self): if self.collapsed: for roller in self.rollers: roller.grid() self.collapse_btn.config(image=self.collapse_img) self.collapsed = False else: for roller in self.rollers: roller.grid_remove() self.collapse_btn.config(image=self.expand_img) width = 28 + self.collapse_btn.winfo_width( ) + self.menu_btn.winfo_width() + self.name_entry.winfo_width() self.config(height=36, width=width) self.collapsed = True def create_menu(self): menu = Menu(self.menu_btn, tearoff=0, postcommand=maintain_group_indices) menu.add_command(label='Add', underline=0, command=self.add_group) menu.add_command(label='Clone', underline=0, command=lambda: self.add_group(clone=True)) menu.add_command(label='Up', underline=0, command=lambda: self.move_group(offset=-1)) menu.add_command(label='Down', underline=0, command=lambda: self.move_group(offset=1)) menu.add_separator() # ------------- menu.add_command(label='Clear history', underline=6, command=self.clear_history) menu.add_command(label='Remove', underline=0, command=self.remove_group) return menu def add_group(self, clone=False): destination_index = self.index + 1 group = RollerGroup(self.mainframe, destination_index) roller_groups.insert(group.index, group) for i in range(destination_index, len(roller_groups)): roller_groups[i].grid(row=i + 1) if clone: for roller in self.rollers: new_roller = Roller(group, self.rollers.index(roller)) new_roller.name.set(roller.name.get()) new_roller.dice_qty.set(roller.dice_qty.get()) new_roller.die_faces.set(roller.die_faces.get()) new_roller.modifier.set(roller.modifier.get()) new_roller.finalmod.set(roller.finalmod.get()) group.rollers.append(new_roller) group.name.set(self.name.get()) else: group.rollers.append(Roller(group, 0)) group.name.set(group.name.get()) maintain_tabstops() self.mainframe.editmenu.entryconfigure( self.mainframe.editmenu.index('end'), command=lambda: self.add_group(clone=clone)) self.mainframe.bind_all('<Control-r>', lambda e: self.add_group(clone=clone)) def move_group(self, offset=0, destination_index=0): if not destination_index: destination_index = self.index + offset if destination_index >= 0: group = roller_groups.pop(self.index) roller_groups.insert(destination_index, group) maintain_group_indices() self.name.set(self.name.get()) self.mainframe.editmenu.entryconfigure( self.mainframe.editmenu.index('end'), command=lambda: self.move_group(offset=offset)) self.mainframe.bind_all('<Control-r>', lambda e: self.move_group(offset=offset)) def clear_history(self): for roller in self.rollers: roller.reset() roller.history = [] self.history_frame.config(text='History') def remove_group(self, override=False): if len(roller_groups) > 1 or override: self.grid_remove() roller_groups.remove(self) self.name.set('') def maintain_roller_indices(self): for roller in self.rollers: roller.index = self.rollers.index(roller) roller.grid(row=roller.index) def roll_group(self): for roller in self.rollers: roller.roll() self.navigate_history() self.mainframe.editmenu.entryconfigure( self.mainframe.editmenu.index('end'), command=lambda: self.roll_group()) self.mainframe.bind_all('<Control-r>', lambda e: self.roll_group()) def navigate_history(self, offset=0, desired_index=0): hist_len = len(self.rollers[0].history) if not hist_len: return if not desired_index: desired_index = self.hist_index + offset if desired_index >= -1 and desired_index <= hist_len: if desired_index == -1: desired_index = 0 if desired_index == hist_len: desired_index = hist_len - 1 for roller in self.rollers: hist_dict = roller.history[desired_index] roller.results = hist_dict['results'] roller.dice_qty.set(hist_dict['dice_qty']) roller.die_faces.set(hist_dict['die_faces']) roller.modifier.set(hist_dict['modifier']) roller.results_text.set(hist_dict['results_text']) roller.finalmod.set(hist_dict['finalmod']) self.history_frame.config(text=hist_dict['timestamp']) self.hist_index = desired_index self.maintain_result_widths() def maintain_result_widths(self): for roller in self.rollers: w = len(roller.results_text.get()) if w > 80: w = 80 roller.results_entry.config(width=w)
class GranMenu(GranSelector): def __init__(self, parent: Widget, chart_manager, color): GranSelector.__init__(self, parent, chart_manager, color) self.gran_var = StringVar() self.menubutton = Menubutton( self, textvariable=self.gran_var, font=Fonts.FIXED_14, width=10, background=color, foreground=color.contrast, bd=0, pady=6, ) self.menu = Menu( self.menubutton, background=color, foreground=color.contrast, font=Fonts.FIXED_14, tearoff=False, ) self.menubutton["menu"] = self.menu for item in self.MENU_LAYOUT: if item is None: self.menu.add_separator() else: self.menu.add_command( label=item.name, command=partial(self.gran_callback, item) ) grid(self.menubutton, 0, 0) def set_gran(self, gran: Optional[Gran]): if gran is None: self.gran_var.set("gran") self.menubutton.config(foreground="grey") else: self.gran_var.set(gran.name) self.menubutton.config(foreground=self.color.contrast) def gran_callback(self, gran: Gran): self.apply_gran(gran) MENU_LAYOUT = ( Gran.M, Gran.W, Gran.D, None, Gran.H12, Gran.H8, Gran.H6, Gran.H4, Gran.H3, Gran.H2, Gran.H1, None, Gran.M30, Gran.M15, Gran.M10, Gran.M5, Gran.M4, Gran.M2, Gran.M1, ) """
#!/usr/bin/env python3 ''' menubutton_sample.py for course material at www.jasaplus.com ''' from tkinter import Tk, Menubutton, Menu, RAISED def page(container): print("Page selected: " + container) window = Tk() window.title("Menubutton sample") window.geometry("600x400+300+10") window.configure(bg="#00aff0") mbutton = Menubutton(window, text="Menu") picks = Menu(mbutton) mbutton.config(menu=picks) picks.add_command(label='Home', command=lambda: page("home")) picks.add_command(label='About', command=lambda: page("about")) picks.add_command(label='Contact', command=lambda: page("contact")) mbutton.place(x=10, y=20) mbutton.config(bg='#ffffff', bd=1, relief=RAISED) window.mainloop()