[Tkinter-discuss] Issue with the layout of a frame

Guilherme Polo ggpolo at gmail.com
Thu Jul 3 14:10:35 CEST 2008


On Thu, Jul 3, 2008 at 2:33 AM, Alexnb <alexnbryan at gmail.com> wrote:
>
> I am in the middle of writing my first big app. I am having trouble with the
> layout of the frames and buttons. In particular, just one frame. I'll post
> the code and you can compile it and see what I am talking about. But, when
> you do there is a red frame with the button "Define" in it. I want this
> frame to be below the yellow and green frame. It has to be a child frame of
> a certain parent frame. I can make it work if it is not in that certain
> parent frame, but can't seem to when it is. Here's the code, and Ill give
> some additional info at the bottom.

I'm sure you can manage to post a much smaller code that shows your
problem. This may also help you understanding the problem, and your
chances of getting help will increase at the same time.

>
> from Tkinter import*
> #Now for the class that gets the definitions
> from get_defs import*
>
> class App:
>    def __init__(self, parent):
>        self.parent = parent
>        self.parent.geometry("500x250")
>
>        #----------------------------Contstants for Buttons------------
>
>        button_padx = "2m"
>        button_pady = "1m"
>
>        #--------------------------end constants-----------------------
>
>        self.baseContainer = Frame(self.parent)
>        self.baseContainer.pack(side=TOP, fill = BOTH, expand=NO)
>
>        #the Top Frame with all the buttons
>        self.topContainer = Frame(self.baseContainer, bg="purple")
>        self.topContainer.pack(side=TOP, expand=YES, ipadx=5,
>                               ipady=5, fill = X, anchor=N)
>
>
>
>        #the frame with the main things the user will use
>        self.mainContainer = Frame(self.baseContainer, bg="blue")
>        self.mainContainer.pack(side=TOP,
>                                ipadx = 5,
>                                ipady = 5,
>                                anchor=CENTER,
>                                expand=YES,
>                                fill=BOTH)
>
>        #---------------------Top Buttons-----------------------------
>            #WORD LIST BUTTON------------------
>        self.wordListButton = Button(self.topContainer, padx=button_padx,
>                                   pady=button_pady)
>        self.wordListButton.configure(text="Word List",
> command=self.define_Frame)
>        self.wordListButton.pack(side=LEFT)
>            #END WORD LIST BUTTON---------------
>
>            #DEFINITIONS BUTTON-----------------
>        self.definitionsButton = Button(self.topContainer,
>                                        padx=button_padx,
>                                        pady=button_pady,
>                                        command = self.defs_Frame)
>        self.definitionsButton.configure(text="Definitions")
>        self.definitionsButton.pack(side=LEFT)
>            #END DEFINITIONS BUTTON--------------
>    def destroyMainChildren(self):
>        #This will make sure taht when a button is pushed for a new set of
> frames
>        #that everything will go smoothly.
>        for widget in self.mainContainer.pack_slaves():
>            widget.destroy()
>    def destroyDefButFrame(self):
>        #The define it button is under a different frame than main frame
>        #so this is another way of killing it.
>        for widget in self.defineButtonF.pack_slaves():
>            widget.destroy()
>        self.defineButtonF.destroy()
>
>
>
>
>    def defs_Frame(self):
>        #Destroy main's children
>        self.destroyMainChildren()
>        self.destroyDefButFrame()
>
>        optionsFrame = Frame(self.mainContainer, bg="red")
>        optionsFrame.pack(side=TOP, expand=YES, ipadx=5,
>                               ipady=5, fill = X, anchor=N)
>
>
>
>
>
>
>        #---------------------DEFINE FRAME------------------------
>        #This frame is the frame that has all the entry widgets, it is
> called
>        #the define frame. when you hit the "wordListButton" this should
> come up
>    def define_Frame(self):
>
>        #Destroy all child widgets
>        self.destroyMainChildren()
>
>
>        myMessage="Please type in all the words that you would like to
> define"
>        Label(self.mainContainer, text=myMessage,
>                    justify=LEFT).pack(side=TOP, anchor=N)
>
>        #The LEFT Frame that comes up when you hit define
>        self.defineContainer1 = Frame(self.mainContainer, bg="green")
>        self.defineContainer1.pack(side=LEFT, ipadx = 5,
>                                    ipady = 5, expand=YES, fill=BOTH)
>
>        #The RIGHT Frame that comes up when you hit define
>        self.defineContainer2 = Frame(self.mainContainer, bg="yellow")
>        self.defineContainer2.pack(side=LEFT, ipadx=5,
>                                    ipady=5, expand=YES, fill=BOTH)
>
>        #This frame is where the define button goes
>        self.defineButtonF = Frame(self.mainContainer, bg="red")
>        self.defineButtonF.pack(side=BOTTOM,
>                                anchor=S,
>                                ipady=5,
>                                ipadx=5,
>                                fill=BOTH,
>                                expand=YES)
>
>
>        #----------------------------Contstants for Buttons------------
>
>        self.button_padx = "2m"
>        self.button_pady = "1m"
>
>        #--------------------------end constants-----------------------
>
>
>
>
>        #----------------------STUFF FOR DEFINE
> FRAME-------------------------
>
>
>        self.e1 = Entry(self.defineContainer1)
>        self.e1.pack(fill=X)
>
>        self.e2 = Entry(self.defineContainer1)
>        self.e2.pack(fill=X)
>
>        self.e3 = Entry(self.defineContainer1)
>        self.e3.pack(fill=X)
>
>        self.e4 = Entry(self.defineContainer1)
>        self.e4.pack(fill=X)
>
>        self.e5 = Entry(self.defineContainer1)
>        self.e5.pack(fill=X)
>
>        self.e6 = Entry(self.defineContainer1)
>        self.e6.pack(fill=X)
>
>        self.e7 = Entry(self.defineContainer1)
>        self.e7.pack(fill=X)
>
>        self.e8 = Entry(self.defineContainer2)
>        self.e8.pack(fill=X)
>
>        self.e9 = Entry(self.defineContainer2)
>        self.e9.pack(fill=X)
>
>        self.e10 = Entry(self.defineContainer2)
>        self.e10.pack(fill=X)
>
>        self.e11 = Entry(self.defineContainer2)
>        self.e11.pack(fill=X)
>
>        self.e12 = Entry(self.defineContainer2)
>        self.e12.pack(fill=X)
>
>        self.e13 = Entry(self.defineContainer2)
>        self.e13.pack(fill=X)
>
>        self.e14 = Entry(self.defineContainer2,)
>        self.e14.pack(fill=X)
>
>        self.listBuffer=[self.e1, self.e2, self.e3, self.e4,
>                         self.e5, self.e6, self.e7, self.e8,
>                         self.e9, self.e10, self.e11,
>                         self.e12, self.e13, self.e14]
>        self.wordList=['None', 'None', 'None', 'None', 'None', 'None',
>                       'None', 'None', 'None', 'None', 'None', 'None',
>                       'None', 'None']
>        self.finalWords=[]
>
>        self.definition1=[]
>        self.definition2=[]
>        self.definition3=[]
>        self.definition4=[]
>        self.definition5=[]
>        self.definition6=[]
>        self.definition7=[]
>        self.definition8=[]
>        self.definition9=[]
>        self.definition10=[]
>        self.definition11=[]
>        self.definition12=[]
>        self.definition13=[]
>        self.definition14=[]
>
>        self.definitionsList=[self.definition1, self.definition2,
> self.definition3,
>                             self.definition4, self.definition5,
> self.definition6,
>                             self.definition7, self.definition8,
> self.definition9,
>                             self.definition10, self.definition11,
> self.definition12,
>                             self.definition13, self.definition14]
>        self.bufferList = []
>
>
> #-------------------------Define Button Stuff-------------------------
>
>        #Define it button
>        self.defineIt= Button(self.defineButtonF, command=self.DefineClick)
>        self.defineIt.configure(text="Define!")
>        self.defineIt.bind("<Return>", self.DefineClickE)
>        self.defineIt.pack(side=TOP,
>                            anchor=N,
>                            padx=self.button_padx,
>                            pady=self.button_pady,)
>    def DefineClickE(self, event):
>        print "Define was hit with Enter"
>        self.DefineClick()
>    def DefineClick(self):
>        print "Define was activated."
>        self.getWords()
>
>    def getWords(self):
>        self.n=0
>        for entry in self.listBuffer:
>            self.wordList[self.n] = entry.get()
>            self.n=self.n + 1
>        for item in self.wordList:
>            if item != '':
>                self.finalWords.append(item)
>        #wordList is the list of all the words, entered or not
>        #print self.wordList
>        #finalWords is the list of words refined, with just the ones the
> user typed
>        #print self.finalWords
>
>
> #----------------------------END DEFINE BUTTON STUFF----------------------
> #-------------------------------------------------------------------------
>        #-----------END OF EVERYTHING FOR THE DEFINE FRAMES-----------
> #-------------------------------------------------------------------------
>
>
>
> root = Tk()
> app = App(root)
> root.mainloop()
>
> there is a button towards the bottom called the defineIt button. this is the
> button in the red frame. If you look right above the big comment called
> constants for buttons, that frame called definebuttonF is the red frame. I
> need the parent to be the mainContainer frame. However, if you make it the
> baseContainer frame. that is what I want it to look like. See if you can
> make it work. I haven't been able to yet. I know this may seem like it would
> take a while; but I really would like it if someone helped.
>
> --
> View this message in context: http://www.nabble.com/Issue-with-the-layout-of-a-frame-tp18252118p18252118.html
> Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>



-- 
-- Guilherme H. Polo Goncalves


More information about the Tkinter-discuss mailing list