我如何将frame.pack()更改为网格形式,以便我可以在整个程序中使用网格
我不断收到“无法在内部使用几何管理器网格。其中已经有由包管理的从属”的错误消息 - 这意味着我不能同时使用包和网格。我不知道如何将frame.pack()更改为可以使用网格的形式。
def __init__(self, master):
frame = Frame(master)
frame.pack()
root.geometry("800x600")
root.title("www.heathhighschool.co.uk/local/secure/management%system")
root.iconbitmap("HeathIcon.ico")
username = Label(frame, text="Username:").grid(row=1, column=0)
username_entry = Entry().grid(row=1, column=1)
passw = Label(frame, text="Password:").grid(row=2, column=0)
I keep getting the error message of "cannot use geometry manager grid inside . which already has slaves managed by pack" - which means i cant use pack and grid together. I dont know how to change frame.pack() into a form where i can use grid.
def __init__(self, master):
frame = Frame(master)
frame.pack()
root.geometry("800x600")
root.title("www.heathhighschool.co.uk/local/secure/management%system")
root.iconbitmap("HeathIcon.ico")
username = Label(frame, text="Username:").grid(row=1, column=0)
username_entry = Entry().grid(row=1, column=1)
passw = Label(frame, text="Password:").grid(row=2, column=0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Entry().grid(row=1, column=1)
Entry 没有位置参数,例如确定 master 的root
或frame
如果没有给出位置参数,则默认设置tk.Tk()
(root)。要解决您的问题,请为您的
Entry
使用不同的母版或使用frame.grid()
另请注意,您可以在每个母版中拥有嵌套布局,您可以在其中使用选择使用
.pack()
或.grid()
。请参阅我的答案,了解 tkinters 几何管理的基本知识。
此外,您的分配将变为
None
,因为.grid()
返回None
,而您希望保留返回的引用>小部件()
:Entry().grid(row=1, column=1)
Entry has no positional argument, such asroot
orframe
which determinates the master and if no positional argument is giventk.Tk()
(root) is set by default.To solve your issue, either use a different master for your
Entry
or useframe.grid()
Also note that you can have in each master a nested layout, within you can choose to use
.pack()
or.grid()
.See my answer here for a basic knowledge of tkinters geometry management.
In addition, your assignment will become
None
since.grid()
returnsNone
, while you want to keep a reference that is returned byWidget()
: