0

I understand you can not mix tkinter's grid() and pack() methods within the same master. However, my understanding was that it is valid to use pack within a frame, and grid within a different frame, even if both of these frames share a common parent? Here is my code for a frame that is packed onto the master root, Why am I receiving the error regarding mixing pack and grid? Sorry if this is just me blindly missing the rules of mixing pack and grid.

Class Login(tk.Frame): 
    def __init__(self, master):
        super().__init__(master)
        self.config()

        rightFrame = tk.Frame(self).pack(side='right') #Using PACK
        leftFrame = tk.Frame(self).pack(side='left') #Using GRID

        # RIGHT SIDE #

        self.photo = tk.PhotoImage(file='temp.png')
        label = tk.Label(rightFrame, image=self.photo)
        label.pack(side='right')

        # LEFT SIDE #

        label = tk.Label(leftFrame, text="Grade Predictor")
        label.config(font=("Courier 22 bold"))
        label.grid(row=0, column=0)

        self.usernameBox = tk.Entry(leftFrame)
        self.usernameBox.grid(row=1, column=0)       

        self.pack(fill='both')
Mattattack
  • 179
  • 6
  • 21

1 Answers1

2

You are creating the left and right frames as:

rightFrame = tk.Frame(self).pack(side='right')

which assigns None to rightFrame as pack() returns None.

If you create them as:

rightFrame = tk.Frame(self)
rightFrame.pack(side='right')

it works just fine.

figbeam
  • 7,001
  • 2
  • 12
  • 18
  • Thanks a lot! Didn't realise. – Mattattack Aug 16 '19 at 12:36
  • Sorry, @figbeam do you know why in the code above if I give leftFrame a fill='both' in its pack method it doesn't seem to fill the y axis? – Mattattack Aug 16 '19 at 12:51
  • Works for me. Try giving the Frame a bg color to see its extent. – figbeam Aug 16 '19 at 12:58
  • Already have a bg colour. If I have the side as left, it will fill y, but leave space between both frames, and if I leave side as its default, it will fill x, but not y? Any idea why? – Mattattack Aug 16 '19 at 13:02
  • I'm not quite sure I understood this completely. I can, however, point you to an excellent description of how pack will distribute child widgets depending on where you want to put them: [Tkinter pack method confusion](https://stackoverflow.com/questions/57390278/tkinter-pack-method-confusion/57396569#57396569). Have a readthrough and see if it explains packing better. – figbeam Aug 16 '19 at 13:07