Shikoki
Shikoki

Reputation: 143

Issues with tkinter grid and pack in separate classes

So I've been working on a group project, some of use used pack and others used grid as a layout manager, I'm making the part of the application that puts everyones code together.

I've been working on a UI using pack, and what I want it to do is when I click on a button, a new tk.Tk() window is launched which then runs its code that is managed by grid.

Here is a snipped of the code to try and show you what I'm doing, I keep getting the error "cannot use the geometry manager grid inside . which already has slaves managed by pack"

def launchQuest(self, questType):
    if(questType == "ham"):
        ham = tk.Tk()
        ham.configure(background='white')
        app = HM(ham)
        ham.mainloop()

If you need to see more code just ask, the whole class is around 400 lines so far but I don't think it is relevant.

Any help would be great!

Thanks!

Upvotes: 1

Views: 325

Answers (2)

dusty
dusty

Reputation: 885

Only one type of positioning (grid, pack, or place) can be used at a time, within a container. Tk() gives you a window (Toplevel) which you use to contain other widgets, some of which can be containers themselves, like Frame, for example. You can pack two frames into a window, but you could not pack one frame and place another into the same window. This limitation only applies one level deep – you could place a frame, and then pack a frame inside that, and then grid inside that, if you wanted. It doesn't matter what method was used to position the container, only at the level of things directly contained by that container.

Upvotes: 0

Marcin
Marcin

Reputation: 238129

Based on my first comment above, the answer is:

There should be only one Tk() root window. If you want other windows, use Toplevel widget.

Upvotes: 3

Related Questions