[Tutor] Frames and the grid manager
Kent Johnson
kent_johnson at skillsoft.com
Tue Aug 24 00:11:47 CEST 2004
Here is a very crude program that demonstrates using two Frames with grids
in them.
Phew, it took me forever to get this to work, I'm a Tkinter newbie myself.
Turns out that Frame(master).grid(row=0) does NOT return the Frame
created...for some reason I always thought it did :-(
Kent
#!/usr/bin/python
from Tkinter import *
def buildInput(master):
fileInputFrame = Frame(master)
fileInputFrame.grid(row=0)
Label(fileInputFrame, text="Input file:").grid(row=0, sticky=W)
Entry(fileInputFrame).grid(row=0, column=1)
Label(fileInputFrame, text="Output file:").grid(row=1, sticky=W)
Entry(fileInputFrame).grid(row=1, column=1)
def buildButtons(master):
buttonFrame = Frame(master)
buttonFrame.grid(row=1)
Button(buttonFrame, text='Testing Testing').grid(row=0)
Label(buttonFrame, text='Some text').grid(row=0, column=1)
Button(buttonFrame, text='Cancel').grid(row=1, column=1)
root = Tk()
buildInput(root)
buildButtons(root)
root.mainloop()
At 08:16 PM 8/23/2004 +0200, Klas Marteleur wrote:
>Hi again
>I feel kind of stupid but dont understand anyway (better to admit it and try
>to learn).
>
>I dont get the frame thing to work... i have tried several ways but i am kind
>of stuck here:
>--------------------------------------
>#!/usr/bin/python
>from Tkinter import *
>import tkFileDialog, sys
>
>class CreateEbom(Frame):
> def __init__(self,master):
> self.myMaster = master
> self.myMaster.title('Tragic Converter Beta 0.3')
> self.buildGUI()
>
> def buildGUI(self):
> fileInputFrame = Frame(self)
> self.inputFile = Label(fileInputFrame, text="Input file:")
> self.inputFile.pack(side=TOP)
> self.outputFile =Label(fileInputFrame, text="Output file:")
> self.outputFile.pack(side=TOP)
>
>root = Tk()
>createebom = CreateEbom(root)
>root.mainloop()
>------------------------------------------
>
>I want to place both labels in a frame, place them internely in that frame
>using grid.
>
>...and place that frame inside my main window using grid.
>
>Please be patient with me... and take it even slower this time.... :)
>
>Thanks everyone
>Klas
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list