Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.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,使用pack:can';不要将页脚栏保持在底部 我试图让一行三个按钮均匀间隔,但因为我使用的是边=“左”和边=“右”< /代码>,其他按钮在中间结束。_Python_Layout_Tkinter - Fatal编程技术网

Python Tkinter,使用pack:can';不要将页脚栏保持在底部 我试图让一行三个按钮均匀间隔,但因为我使用的是边=“左”和边=“右”< /代码>,其他按钮在中间结束。

Python Tkinter,使用pack:can';不要将页脚栏保持在底部 我试图让一行三个按钮均匀间隔,但因为我使用的是边=“左”和边=“右”< /代码>,其他按钮在中间结束。,python,layout,tkinter,Python,Layout,Tkinter,示例代码: 将tkinter作为tki导入 class App(object): def __init__(self): self.root = tki.Tk() self.root.config(bg="white") self.root.geometry("400x300") top_frm = tki.Frame(self.root).pack() T = tki.Text(top_frm, h

示例代码: 将tkinter作为tki导入

class App(object):

    def __init__(self):

        self.root = tki.Tk()
        self.root.config(bg="white")
        self.root.geometry("400x300")


        top_frm = tki.Frame(self.root).pack()
        T = tki.Text(top_frm, height=2, width=30)
        T.pack()
        T.insert(tki.END, "Just a text Widget\nin two lines\n")

        mdl_frm = tki.Frame(self.root, width="400").pack(fill="both",expand=True)

        lbut = tki.Button(mdl_frm, text='Left button').pack(side="left")
        rbut = tki.Button(mdl_frm, text='right button').pack(side="right")

        bottom_frm = tki.Frame(self.root).pack(side="bottom",fill="x",expand=False)

        btn_frm_r = tki.Frame(bottom_frm).pack(side="right",fill="x")
        btn_frm_c = tki.Frame(bottom_frm).pack(side="right",fill="x")
        btn_frm_l = tki.Frame(bottom_frm).pack(side="right",fill="x")
        button1 = tki.Button(btn_frm_r,text='Bottom button 1').pack()
        button2 = tki.Button(btn_frm_c,text='Bottom button 2').pack()
        button3 = tki.Button(btn_frm_l,text='Bottom button 3').pack()

app = App()
#launch the app
app.root.mainloop() 
我试着把“左键”和“右键”放在一个框架里。 我在某个地方读到,当使用
side
声明时,当给定某个区域时,它会完全控制该区域,因此我尝试先声明
btm\u frm
帧,然后使用
side=“bottom”

有什么想法吗?

.pack()
返回
None
,因此不能
.pack()
并在一行上赋值给变量。
此外,我建议在您将其他物品放入框架后将其打包。
最后,我建议对类属性使用
self.
;当您以后需要访问它们时,您会发现它很有用

import tkinter as tki

class App(object):

    def __init__(self):

        self.root = tki.Tk()
        self.root.config(bg="white")
        self.root.geometry("400x300")


        self.top_frm = tki.Frame(self.root)
        self.top_frm.pack()
        self.T = tki.Text(self.top_frm, height=2, width=30)
        self.T.pack()
        self.T.insert(tki.END, "Just a text Widget\nin two lines\n")

        self.mdl_frm = tki.Frame(self.root, width="400")
        self.mdl_frm.pack(fill="both",expand=True)

        self.lbut = tki.Button(self.mdl_frm, text='Left button')
        self.lbut.pack(side="left")
        self.rbut = tki.Button(self.mdl_frm, text='right button')
        self.rbut.pack(side="right")

        self.bottom_frm = tki.Frame(self.root)

        self.btn_frm_r = tki.Frame(self.bottom_frm)
        self.btn_frm_r.pack(side="right",fill="x")
        self.btn_frm_c = tki.Frame(self.bottom_frm)
        self.btn_frm_c.pack(side="right",fill="x")
        self.btn_frm_l = tki.Frame(self.bottom_frm)
        self.btn_frm_l.pack(side="right",fill="x")
        self.button1 = tki.Button(self.btn_frm_r,text='Bottom button 1')
        self.button1.pack()
        self.button2 = tki.Button(self.btn_frm_c,text='Bottom button 2')
        self.button2.pack()
        self.button3 = tki.Button(self.btn_frm_l,text='Bottom button 3')
        self.button3.pack()

        self.bottom_frm.pack(side="bottom",fill="x",expand=False)



app = App()
#launch the app
app.root.mainloop()
.pack()
返回
None
,因此不能
.pack()
并在一行上赋值给变量。
此外,我建议在您将其他物品放入框架后将其打包。
最后,我建议对类属性使用
self.
;当您以后需要访问它们时,您会发现它很有用

import tkinter as tki

class App(object):

    def __init__(self):

        self.root = tki.Tk()
        self.root.config(bg="white")
        self.root.geometry("400x300")


        self.top_frm = tki.Frame(self.root)
        self.top_frm.pack()
        self.T = tki.Text(self.top_frm, height=2, width=30)
        self.T.pack()
        self.T.insert(tki.END, "Just a text Widget\nin two lines\n")

        self.mdl_frm = tki.Frame(self.root, width="400")
        self.mdl_frm.pack(fill="both",expand=True)

        self.lbut = tki.Button(self.mdl_frm, text='Left button')
        self.lbut.pack(side="left")
        self.rbut = tki.Button(self.mdl_frm, text='right button')
        self.rbut.pack(side="right")

        self.bottom_frm = tki.Frame(self.root)

        self.btn_frm_r = tki.Frame(self.bottom_frm)
        self.btn_frm_r.pack(side="right",fill="x")
        self.btn_frm_c = tki.Frame(self.bottom_frm)
        self.btn_frm_c.pack(side="right",fill="x")
        self.btn_frm_l = tki.Frame(self.bottom_frm)
        self.btn_frm_l.pack(side="right",fill="x")
        self.button1 = tki.Button(self.btn_frm_r,text='Bottom button 1')
        self.button1.pack()
        self.button2 = tki.Button(self.btn_frm_c,text='Bottom button 2')
        self.button2.pack()
        self.button3 = tki.Button(self.btn_frm_l,text='Bottom button 3')
        self.button3.pack()

        self.bottom_frm.pack(side="bottom",fill="x",expand=False)



app = App()
#launch the app
app.root.mainloop()

对按钮使用
side='left'
side='right'
,因为您希望它们在其包含的框架内从左向右移动

    button1 = tki.Button(btn_frm_r,text='Bottom button 1').pack(side="left")
    button2 = tki.Button(btn_frm_c,text='Bottom button 2').pack(side="left")
    button3 = tki.Button(btn_frm_l,text='Bottom button 3').pack(side="left")
顺便说一下,如果您要执行
tki.Button(…).pack(…)
,那么将其指定给变量是没有意义的。变量将始终具有值
None


pack
算法的完整解释如下:

对按钮使用
side='left'
side='right'
,因为您希望它们在其包含的框架内从左向右移动

    button1 = tki.Button(btn_frm_r,text='Bottom button 1').pack(side="left")
    button2 = tki.Button(btn_frm_c,text='Bottom button 2').pack(side="left")
    button3 = tki.Button(btn_frm_l,text='Bottom button 3').pack(side="left")
顺便说一下,如果您要执行
tki.Button(…).pack(…)
,那么将其指定给变量是没有意义的。变量将始终具有值
None

pack
算法的完整解释如下: