Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python _tkinter.TclError:无法在内部使用几何图形管理器栅格。这里已经有了由packenter代码管理的奴隶_Python_Tkinter - Fatal编程技术网

Python _tkinter.TclError:无法在内部使用几何图形管理器栅格。这里已经有了由packenter代码管理的奴隶

Python _tkinter.TclError:无法在内部使用几何图形管理器栅格。这里已经有了由packenter代码管理的奴隶,python,tkinter,Python,Tkinter,我正在尝试创建一个基于入口小部件的子小部件。 不幸的是,它没有像我认为的那样工作。 从以下代码: import tkinter as tk WINDOW_WIDTH = 800 WINDOW_HEIGHT = 600 class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.pack() sel

我正在尝试创建一个基于入口小部件的子小部件。 不幸的是,它没有像我认为的那样工作。 从以下代码:

import tkinter as tk

WINDOW_WIDTH = 800
WINDOW_HEIGHT = 600


class Application(tk.Frame):

    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.pack()
        self.createWidgets()

    def createWidgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "SOLVE"
        self.hi_there.grid(row=1, column=1)

        self.QUIT = tk.Button(
            self, text="QUIT", fg="red", command=self.master.quit)
        self.QUIT.grid(row=1, column=2)

        # self.number_box = tk.Entry(self) # This is working
        self.number_box = NumberBox(self)  # this is not working
        self.number_box.grid(row=2, column=1)


class MainWindow():

    def __init__(self):
        #self.root = tk.Tk()
        self.app = Application()
        self.app.master.title("SUDOKU")
        self.app.master.minsize(width=WINDOW_WIDTH, height=WINDOW_HEIGHT)
        self.app.master.maxsize(width=WINDOW_WIDTH, height=WINDOW_HEIGHT)
        self.app.mainloop()


class NumberBox(tk.Entry):

    def __init__(self, master=None, cnf={}, **kw):

        super().__init__(cnf, kw)
        #self.text = tk.StringVar()


window = MainWindow()
我得到一个错误:

回溯(最近一次呼叫最后一次):
文件“E:/workspace/python/sudoku/gui/guitk.py”,第42行,在
窗口=主窗口()
文件“E:/workspace/python/sudoku/gui/guitk.py”,第28行,在__
self.app=应用程序()
文件“E:/workspace/python/sudoku/gui/guitk.py”,第11行,在__
self.createWidgets()
createWidgets中的文件“E:/workspace/python/sudoku/gui/guitk.py”,第22行
self.number\u box.grid(行=2,列=1)
文件“C:\Python34\lib\tkinter\\uuuu init\uuuuu.py”,第2057行,在网格中
+自选配件(cnf,kw))
_tkinter.TclError:无法在内部使用几何图形管理器栅格。这里已经有由packenter代码管理的从机

当我直接使用Entry类(而不是NumberBox,请参见注释行)时,代码正在工作。从我的类工作不正常的条目继承有什么不对。

您的
super()
调用看起来有问题。您需要传递父窗口小部件并传递未打包的关键字参数,如下所示:

super().__init__(master, cnf, **kw)

请修正你的缩进。如果我用self.grid()替换self.pack(),你的代码在我的计算机上运行(Python 3.4.1 | Anaconda 2.1.0(64位)self.pack()运行正常,但这不是我的解决方案。我想使用网格布局。在你发布的代码中,有一个self.pack…是的,它是self.pack()的唯一一个实例),我忘了换了,反正奇怪的是它还在工作。