# -*- coding: utf-8 -*- import tkinter as tk import tkinter.ttk as ttk root = tk.Tk() root.title("tk27.py") root.geometry("300x250") ##################################### def formb1(): if openVar.get() == 1: tk.filedialog.askopenfilename(title = 'Open') openVar.set(0) if saveVar.get() == 1: tk.filedialog.askopenfilename(title = 'Save') saveVar.set(0) topFrame = tk.Frame(root, bg = 'lightgrey') mb1 = tk.Menubutton(topFrame, text = "File", relief = 'raised') mb1.menu = tk.Menu(mb1, tearoff = 0, bg = 'lightyellow', activeforeground = 'blue', activebackground = 'pink') mb1["menu"] = mb1.menu openVar = tk.IntVar() mb1.menu.add_checkbutton(label = 'Open', variable = openVar, command = formb1) mb1.menu.add_separator() saveVar = tk.IntVar() mb1.menu.add_checkbutton(label = 'Save', variable = saveVar, command = formb1) mb1.grid(row = 0, column = 0) def formb2(): if helpVar.get() == 1: tk.messagebox.showinfo("Help", "Version 1.0") helpVar.set(0) if searchVar.get() == 1: tk.messagebox.showinfo("Search","Searching...") searchVar.set(0) mb2 = tk.Menubutton(topFrame, text = 'Help', relief = 'raised') mb2.help = tk.Menu(mb2) mb2["menu"] = mb2.help helpVar = tk.IntVar() mb2.help.add_checkbutton(label = 'Help', variable = helpVar, command = formb2) searchVar = tk.IntVar() mb2.help.add_checkbutton(label = 'Search', variable = searchVar, command = formb2) mb2.grid(row = 0, column = 1) topFrame.pack(fill = tk.X) #------------------------------------ ttk.Style().configure('TFrame', background = 'lightpink') ttk.Style().configure('TMenubutton', font = "Times 10 bold", foreground = 'blue') bottomFrame = ttk.Frame(root, style = 'TFrame') mb3 = ttk.Menubutton(bottomFrame, text = 'Edit') mb3.menu = tk.Menu(mb3, tearoff = 0) mb3["menu"] = mb3.menu mb3.menu.add_command(label = 'Copy', command = lambda: tk.messagebox.showinfo("Copy", "Copying...")) mb3.menu.add_command(label = 'Paste', command = lambda: tk.messagebox.showinfo("Paste", "Pasting...")) mb3.grid(row = 0, column = 0) mb4 = ttk.Menubutton(bottomFrame, text = 'Source') mb4.menu = tk.Menu(mb4, tearoff = 0) mb4["menu"] = mb4.menu mb4.menu.add_command(label = 'Source A', command = lambda: tk.messagebox.showinfo("A", "Obtaining Source A...")) mb4.menu.add_command(label = 'Source B', command = lambda: tk.messagebox.showinfo("B", "Obtaining Source B...")) mb4.grid(row = 0, column = 1) bottomFrame.pack(side = tk.BOTTOM, fill = tk.X) ##################################### root.mainloop()