TkInter 网格函数错误信息

TkInter grid function error message

我正在尝试 运行 以下代码:

from tkinter import *

root = Tk()

topFrame = Frame(root)
topFrame.pack(side=TOP)
leftFrame = Frame(root)
leftFrame.pack(side=LEFT)
botFrame = Frame(root)
botFrame.pack(side=BOTTOM)

button1 = Button(leftFrame, text="Button 1", fg="Black")
button2 = Button(leftFrame, text="Button 2", fg="Black")
button3 = Button(leftFrame, text="Button 3", fg="Black")

button1.grid(row=0, column=0)
button2.grid(row=1, column=0)
button3.grid(row=2, column=0)

ScaleWidget = Scale(root, from_=0, to=100)
ScaleWidget.grid(row=0, column=1)

ScaleWidget = Scale(root, from_=0, to=100, orient=HORIZONTAL)
ScaleWidget.grid(row=0, column=1)

root.mainloop()

但是我收到以下错误消息:

D:\Python\python.exe D:/untitled/TkInter_Frame_Full_GUI.py
Traceback (most recent call last):
  File "D:/untitled/TkInter_Frame_Full_GUI.py", line 21, in <module>
    ScaleWidget.grid(row=0, column=1)
  File "D:\Python\lib\tkinter\__init__.py", line 2057, in grid_configure
    + self._options(cnf, kw))
_tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack

我不确定该怎么做,非常感谢您的帮助,谢谢!

您不应该混合 windows 的网格和包管理器,它们共享一个共同的父级:

Warning: Never mix grid and pack in the same master window. Tkinter will happily spend the rest of your lifetime trying to negotiate a solution that both managers are happy with. Instead of waiting, kill the application, and take another look at your code. A common mistake is to use the wrong parent for some of the widgets.

来源:http://effbot.org/tkinterbook/grid.htm