修复此代码'不能在内部使用几何管理器网格.已经有由包管理的奴隶' [英] fix this code 'cannot use geometry manager grid inside . which already has slaves managed by pack'

查看:25
本文介绍了修复此代码'不能在内部使用几何管理器网格.已经有由包管理的奴隶'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 grid() 编写了这个简单的代码,但似乎有问题并显示错误:

I wrote this simple code using grid(), but there seem to be a problem and shows the error :

class Input_screen:

    def __init__(self,master):
        frame = Frame(master)
        frame.pack()

        self.name_lable = Label(frame,text = 'NAME')
        self.name_e = Entry(root)

        self.name_lable.grid(row=1,column=0,sticky=W)
        self.name_e.grid(row=1,column=1)    

root = Tk()
b = Input_screen(root)
root.mainloop()

TclError: 不能在 内部使用几何管理器网格.已经有由包管理的奴隶

TclError: cannot use geometry manager grid inside . which already has slaves managed by pack

推荐答案

错误告诉你到底哪里出了问题:你不能同时使用 packgrid具有共享公共父级的小部件.在这种情况下,共同的父母是.".这是根小部件的内部名称.

The error is telling you exactly what is wrong: you can't use both pack and grid with widgets that share a common parent. In this case, the common parent is "." which is the internal name for the root widget.

您正在使用 pack 作为 framegrid 作为 self.name_e,并且两者都有根窗口作为它们的父窗口.您需要为两者使用 grid 或为两者使用 pack.

You're using pack for frame and grid for self.name_e, and both of those have the root window as their parent. You either need to use grid for both or pack for both.

这篇关于修复此代码'不能在内部使用几何管理器网格.已经有由包管理的奴隶'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆