gui.py
# last updated 29-Jul-2008 -- dmreagan from Tkinter import * class BaseGui(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) # do superclass init self.alignment = "Top" self.canvases = [] self.MakeWidgets() # attach widgets to self self.SetGeometry() self.SetBindings() def MakeWidgets(self): self.buttonBar = Frame(self, relief = RAISED, borderwidth = 2) self.buttonBar.quit = Button(self.buttonBar, text='Quit', command=self.master.destroy) self.barButton = Button(self, command=self.moveCanvas) self.buttonBar.new = Button(self.buttonBar, text='New', command=self.New) self.buttonBar.open = Button(self.buttonBar, text='Open', command=self.Open) self.buttonBar.save = Button(self.buttonBar, text='Save', command=self.Save) self.canvas = Canvas(self, borderwidth=2, width=340, height=230, relief = SUNKEN) i = 0 while i < 9: self.canvases.append( Canvas(self, borderwidth=2, width=85, height=57, relief = RIDGE) ) i = i + 1 self.maxCdLabel = Label(self, text = "Max Cd: ") self.bafaLabel = Label(self, text = "BA/FA: ", foreground = "#444") self.baLabel = Label(self, text = "B/A: ", foreground = "#800") self.faLabel = Label(self, text = "F/A: ", foreground = "#060") self.caLabel = Label(self, text = "C/A: ", foreground = "#008") self.biLabel = Label(self, text = "bi") self.boLabel = Label(self, text = "bo") def SetGeometry(self): self.master.maxsize(520,500) self.master.minsize(520,500) self.pack(fill=BOTH, expand=1) self.buttonBar.place(anchor=NW, x=0, y=0, height = 40, width = 520) self.buttonBar.quit.place(x=455, y=5) self.buttonBar.new.place(x=5,y=5) self.buttonBar.open.place(x=75,y=5) self.buttonBar.save.place(x=150,y=5) self.barButton.place(x=0,y=417,height = 10, width = 520) self.canvas.place(x=90,y=110) self.canvases[0].place(x=5,y=45) self.canvases[1].place(x=220,y=45) self.canvases[2].place(x=425,y=45) self.canvases[3].place(x=5,y=350) self.canvases[4].place(x=220,y=350) self.canvases[5].place(x=425,y=350) self.canvases[6].place(x=5,y=430) self.canvases[7].place(x=220,y=430) self.canvases[8].place(x=425,y=430) self.maxCdLabel.place(x=5,y=125) self.bafaLabel.place(x=5, y=180) self.baLabel.place(x=5, y=240) self.faLabel.place(x=5, y=280) self.caLabel.place(x=5, y=320) self.biLabel.place(x=75, y=110) self.boLabel.place(x=435, y=110) def SetBindings(self): self.buttonBar.quit.bind("<Control-q>", self.quit) def moveCanvas(self): if (self.alignment == "Top"): self.alignment = "Bottom" self.barButton.place(y="112") self.canvases[3].place(y="125") self.canvases[4].place(y="125") self.canvases[5].place(y="125") self.canvas.place(y="190") self.maxCdLabel.place(y=205) self.bafaLabel.place(y=260) self.baLabel.place(y=320) self.faLabel.place(y=360) self.caLabel.place(y=400) self.biLabel.place(y=190) self.boLabel.place(y=190) else: self.alignment = "Top" self.canvas.place(y="110") self.canvases[5].place(y="350") self.canvases[4].place(y="350") self.canvases[3].place(y="350") self.barButton.place(y="417") self.maxCdLabel.place(y=125) self.bafaLabel.place(y=180) self.baLabel.place(y=240) self.faLabel.place(y=280) self.caLabel.place(y=320) self.biLabel.place(y=110) self.boLabel.place(y=110) def New(self): # function for new button self.ErrorDialog("New") def Open(self): self.ErrorDialog("Open") def Save(self): self.ErrorDialog("Save") def ErrorDialog(self, button): top = Toplevel() Label(top, text='Error: called "'+button+'" in base class').pack(anchor=N) Button(top, text='OK', command=top.destroy).pack(anchor=S) top.grab_set() top.focus_set() top.wait_window() if __name__ == '__main__': BaseGui().mainloop()
by
AMcneil
—
last modified
Feb 29, 2016 12:25 PM