from tkinter import * from tkinter.ttk import * from tkinter import Menubutton from dialogs import ConnectionDialog class ApplicationMenu: def __init__(self, root): ### # Make a reference to the tk root window in the ApplicationMenu self.root = root ### # Create the menubar self.menubar = Frame(self.root, relief=RAISED, borderwidth=1) self.menubar.pack(anchor=N, fill=X) self.filemenu = Menubutton(self.menubar, text="File", underline=0, ) self.filemenu.pack(side=LEFT) self.filemenu.menu = Menu(self.filemenu, tearoff=False) # Create the "File" menu self.filemenu.menu.add_command(label="New...", accelerator="Ctrl+N", command=self.new, ) self.filemenu.menu.add_command(label="Open...", accelerator="Ctrl+O", command=self.open_, ) self.filemenu.menu.add_command(label="Import...", command=self.import_, accelerator="Ctrl+I", ) self.filemenu.menu.add_separator() self.filemenu.menu.add_command(label="Export...", command=self.export, accelerator="Ctrl+E", ) self.filemenu.menu.add_separator() self.filemenu.menu.add_command(label="Save", command=self.save, accelerator="Ctrl+S", ) self.filemenu.menu.add_separator() self.filemenu.menu.add_command(label="Quit", command=root.quit, accelerator="Ctrl+Q", ) # Create the "Edit" menu self.editmenu = Menubutton(self.menubar, text="Edit", underline=0) self.editmenu.pack(side=LEFT) self.editmenu.menu = Menu(self.editmenu, tearoff=False) self.editmenu.menu.add_command(label="Settings...", command=self.settings, ) # Add the menus to the menubar self.filemenu["menu"] = self.filemenu.menu self.editmenu["menu"] = self.editmenu.menu # Bind events to the methods "enabling" the accelerators self.root.bind("", self.open_, ) self.root.bind("", self.quit, ) self.root.bind("", self.location, ) ### # The functions def location(self, event=None): print(dir(event)) self.filemenu.tk_popup(event.x_root,event.y_root) def open_(self, event=None): """Opens up a database connection dialog to establish a connection to an existing database """ ConnectionDialog(self.root) def new(self,event=None): """Creates a new database and connects to it """ print(dir(event)) pass def import_(self, event=None): pass def export(self, event=None): pass def save(self, event=None): pass def close(self, event=None): pass def quit(self,event=None): ### # TODO # A check to see if there are unsaved changes in the # application before exit needs to be implemented. self.root.destroy() def settings(self, event=None): pass