【问题标题】:Tkinter cannot use geometry manager grid insideTkinter 不能在内部使用几何管理器网格
【发布时间】:2020-06-10 22:43:41
【问题描述】:

当下面的代码运行时,小部件通常可以工作

Label(window, image=photo1, bg="black").grid(row=0, column=0, sticky=E)

代码给了我错误:

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

我知道这个错误是关于同时使用 .pack 和 .grid 但它在没有这条线的情况下工作,它也同时使用了 .pack 和 .grid

def widgets(self):
        self.head = Label(self.master,text=" Welcome to Luxury Cruises ", font=('freesansbold', 25),pady=40)
        self.head.pack()

        self.logf = Frame(self.master, padx=10, pady=10)
        Label(self.logf, text="Username: ", font=('freesansbold', 20), padx=5, pady=10).grid(sticky=W)
        Entry(self.logf, textvariable=self.username, bd=8, font=('calibri', 15, 'bold')).grid(row=0, column=1, sticky=E)
        Label(self.logf, text="Password: ", font=('freesansbold', 20), padx=5, pady=10).grid(row=1, column=0, sticky=W)
        Entry(self.logf, textvariable=self.password, bd=8, font=('calibri', 15, 'bold'), show="*").grid(row=1, column=1,
                                                                                               sticky=E)
        Button(self.logf, text=" Login ", bd=7, font=("monaco", 15, 'bold'), padx=5, pady=5, command=self.login).grid(
            row=2)
        Button(self.logf, text=" Make Account ", bd=7, font=("monaco", 15, 'bold'), padx=5, pady=5,
               command=self.cr).grid(row=2, column=1)
        self.logf.pack()

【问题讨论】:

  • 你所说的 pack() 和 grid() 一起工作,因为它们在不同的容器中使用。

标签: python tkinter


【解决方案1】:

当您使用.pack() 函数时,您不能使用.grid() 函数。

查看When to use pack or grid layouts in tkinter?

【讨论】:

  • 不完全正确。您不能在同一个容器中使用 2。但是您可以说,例如打包一个框架,然后对该框架中的所有内容进行网格化。 packgrid 也是方法而不是函数。
猜你喜欢
  • 1970-01-01
  • 2017-03-27
  • 1970-01-01
  • 2014-10-11
  • 2015-07-19
  • 2020-01-24
  • 1970-01-01
  • 1970-01-01
  • 2019-05-05
相关资源
最近更新 更多