简体   繁体   English

tkinter grid和pack在单独的类中的问题

[英]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. 我一直在使用pack工作的UI,我想要它做的是当我点击一个按钮时,启动一个新的tk.Tk()窗口然后运行由网格管理的代码。

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. 如果您需要查看更多代码,那么到目前为止整个班级大约有400行,但我认为它不相关。

Any help would be great! 任何帮助都会很棒!

Thanks! 谢谢!

Based on my first comment above, the answer is: 根据我上面的第一条评论,答案是:

There should be only one Tk() root window. 应该只有一个Tk()根窗口。 If you want other windows, use Toplevel widget. 如果您想要其他窗口,请使用Toplevel小部件。

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. Tk()为您提供了一个窗口(Toplevel),您可以使用它来包含其他窗口小部件,其中一些窗口小部件本身可以是容器,例如Frame。 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. 使用什么方法来定位容器并不重要,只是在容器直接包含的东西的水平上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM