简体   繁体   English

在Tkinter的儿童中打包和网格

[英]Pack and grid within children's children in tkinter

I understand you can not mix tkinter's grid() and pack() methods within the same master. 我知道您不能在同一主机中混用tkinter的grid()和pack()方法。 However, my understanding was that it is valid to use pack within a frame, and grid within a different frame, even if both of these frames share a common parent? 但是,我的理解是,即使这两个框架共享同一个父对象,在一个框架内使用pack并在另一个框架内使用网格也是有效的吗? Here is my code for a frame that is packed onto the master root, Why am I receiving the error regarding mixing pack and grid? 这是我打包到主根目录上的框架的代码,为什么我收到有关混合包和网格的错误? Sorry if this is just me blindly missing the rules of mixing pack and grid. 抱歉,如果这只是我盲目地缺少混合包和网格的规则。

Class Login(tk.Frame): 
    def __init__(self, master):
        super().__init__(master)
        self.config()

        rightFrame = tk.Frame(self).pack(side='right') #Using PACK
        leftFrame = tk.Frame(self).pack(side='left') #Using GRID

        # RIGHT SIDE #

        self.photo = tk.PhotoImage(file='temp.png')
        label = tk.Label(rightFrame, image=self.photo)
        label.pack(side='right')

        # LEFT SIDE #

        label = tk.Label(leftFrame, text="Grade Predictor")
        label.config(font=("Courier 22 bold"))
        label.grid(row=0, column=0)

        self.usernameBox = tk.Entry(leftFrame)
        self.usernameBox.grid(row=1, column=0)       

        self.pack(fill='both')

You are creating the left and right frames as: 您将创建左右框架为:

rightFrame = tk.Frame(self).pack(side='right')

which assigns None to rightFrame as pack() returns None . 它将None分配给rightFrame因为pack()返回None

If you create them as: 如果将它们创建为:

rightFrame = tk.Frame(self)
rightFrame.pack(side='right')

it works just fine. 它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM