-1

I want to use grid to position frames in root, and use pack to position button in first frame. The master window is different, so why do I get this error?

root = Tk()

frame1 = LabelFrame(root, text="Frame1").grid(row=0, column=0)
frame2 = LabelFrame(root, text="Frame2").grid(row=0, column=1)


def open_file():
    pass

btn_import_image = Button(frame1, text="Import", command=open_file)
btn_import_image.pack()


root.mainloop()

Error:

_tkinter.TclError: cannot use geometry manager pack inside . which already has slaves managed by grid
martineau
  • 119,623
  • 25
  • 170
  • 301
I.P.
  • 300
  • 2
  • 16
  • Please examine the value of `frame1`. It's not what you think it is. This question has been asked many times on this site. – Bryan Oakley Nov 12 '21 at 22:18
  • @BryanOakley I do not agree. This "many times" relates to mixing master windows, which I am not doing. – I.P. Nov 12 '21 at 22:25
  • 2
    Yes, you are. Did you examine `frame1` to see what it is? It is `None`. Using it as a parent has the exact same effect as setting the parent to `root`. – Bryan Oakley Nov 12 '21 at 22:33
  • Oh........ Indeed.. Sorry and thank you. I thought about different kind of mistake. – I.P. Nov 12 '21 at 22:36

1 Answers1

0

As @Bryan Oakley pointed out in the comment, using grid() returns None. So to fix it I had to separate instructions:

    frame1 = LabelFrame(root, text="Frame1")
    frame2 = LabelFrame(root, text="Frame2")

    frame1.grid(row=0, column=0)
    frame2.grid(row=0, column=1)

I.P.
  • 300
  • 2
  • 16