Help With Button Layout
Kenneth Gomez
kennethg at pd.jaring.my
Sun Dec 8 19:17:33 EST 2002
Hello,
I am creating a simple GUI. However, I am having problems getting my
buttons to lay side by side. Do you know why my first two buttons are
spaced out so far.
Also, how do I get my menu, buttons and all to start at the top, left
hand corner, instead of the center of the canvas?
Basically, my layout is as follows :
Row 0 is the File menu
Row 1 is filled with buttons
Row 2 has two canvases, one start at column 0 and fills two columns
(i.e. column 0 and 1), the other starts in column 2 and fills 5
columns
Row 3 is an entry which fills 5 columns
Thanking you in advance.
*******
# Create FEM GUI
# Date : December 9, 2002 6.23 a.m.
from Tkinter import *
import Pmw
import sys
class FemGui(Frame):
""" This class creates the GUI for the FEM program. """
def __init__(self):
""" Initialize GUI """
Frame.__init__(self)
Pmw.initialise()
self.createFrame()
self.createMenu()
self.createButtons()
self.createCanvas()
self.createInputRow()
def createFrame(self):
""" Creating the main frame """
# self.master.rowconfigure(0,weight=1)
# self.master.columnconfigure(0,weight=1)
self.master.title ("FEM - Gui")
self.master.geometry("800x600")
self.grid(sticky = W+E+N+S)
def createMenu(self) :
""" Creating the top level Menu """
self.myBalloon = Pmw.Balloon(self)
self.choices = Pmw.MenuBar(self, balloon = self.myBalloon)
# self.choices.pack(fill = X)
self.choices.grid(sticky = W+E+N)
#create File menu and items
self.choices.addmenu("File","Exit")
self.choices.addmenuitem("File","command", command =
self.closeDemo,
label = "Exit")
#create Format menu and items
self.choices.addmenu("Format", "Change font/color")
self.choices.addcascademenu("Format","Color")
self.choices.addmenuitem("Format","separator")
self.choices.addcascademenu("Format", "Font")
#create Help menu and items
self.choices.addmenu("Help","Help")
self.choices.addmenuitem("Help","command", command =
self.openHelp,
label = "Help F1")
def createButtons(self):
""" Creating the top level buttons """
self.geomButton = Button(self, text="Geometry",
command=self.geomIcons)
self.geomButton.grid(row=1, column=0, sticky = W)
self.meshButton = Button(self, text="Mesh",
command=self.geomIcons)
self.meshButton.grid(row=1, column=1, sticky = W)
self.lbcButton = Button(self, text="Load / Boundary
Conditions", command=self.geomIcons)
self.lbcButton.grid(row=1, column=2, sticky = W)
self.matButton = Button(self, text="Material",
command=self.geomIcons)
self.matButton.grid(row=1, column=3, sticky = W)
self.propButton = Button(self, text="Propeties",
command=self.geomIcons)
self.propButton.grid(row=1, column=4, sticky = W)
self.analysisButton = Button(self, text="Analyze",
command=self.geomIcons)
self.analysisButton.grid(row=1, column=5, sticky = W)
self.resultButton = Button(self, text="Results",
command=self.geomIcons)
self.resultButton.grid(row=1, column=6, sticky = W)
self.grid()
def createCanvas(self):
""" Main drawing canvas """
self.mainCanvas = Canvas(self)
self.mainCanvas.grid(row=2, column = 2, columnspan=5,
sticky=W+E+S+N)
""" Canvas to hold icons """
self.iconCanvas = Canvas(self)
self.iconCanvas.grid(row=2, column=0, columnspan = 2,
sticky=W+E+N+S)
def createInputRow(self):
""" Text Input Row at bottom of screen """
self.textEntry = Entry(self)
self.textEntry.grid(row=3, columnspan=7, sticky=W+E+S+N)
def closeDemo(self) :
sys.exit()
def openHelp(self):
pass
def geomIcons(self):
pass
def main():
FemGui().mainloop()
if __name__ == "__main__":
main()
*******
Cheers,
Kenneth Gomez.
More information about the Python-list
mailing list