Python 标签小部件在tkinter中不会在帧内移动 我对TKiTter很新,但是我现在已经练习了一点,但是每当我试图通过指定行和列来在格的框架中移动一个标签时,标签就停留在中间。p>
在下面的代码中,我尝试为位于中上部框架中的名称标签指定行和列,但它从不移动。它只是停留在中间。Python 标签小部件在tkinter中不会在帧内移动 我对TKiTter很新,但是我现在已经练习了一点,但是每当我试图通过指定行和列来在格的框架中移动一个标签时,标签就停留在中间。p>,python,tkinter,Python,Tkinter,在下面的代码中,我尝试为位于中上部框架中的名称标签指定行和列,但它从不移动。它只是停留在中间。 from tkinter import* root=Tk() frame_topleft = Frame(root, height=150, width=50, bg = "green") frame_topmiddle = Frame(root, height=150, width=250, bg="red") frame_topright = Frame(root, height=150, w
from tkinter import*
root=Tk()
frame_topleft = Frame(root, height=150, width=50, bg = "green")
frame_topmiddle = Frame(root, height=150, width=250, bg="red")
frame_topright = Frame(root, height=150, width=250, bg="green")
frame_bottomleft = Frame(root, height=300, width=50, bg="blue")
frame_bottommiddle = Frame(root, height=300, width=250, bg="yellow")
frame_bottomright = Frame(root, height=300, width=250, bg="blue")
label_name=Label(frame_topmiddle, text="Name", font="halvetica")
label_phone=Label(frame_topmiddle, text="Phone", font="halvetica")
frame_topmiddle.grid(row=0, column=1)
frame_topleft.grid(row=0, column=0)
frame_topright.grid(row=0, column=2)
frame_bottomleft.grid(row=1, column=0)
frame_bottommiddle.grid(row=1, column=1)
frame_bottomright.grid(row=1, column=2)
label_name.grid(row=0, column=0)
root.mainloop()
所以,我只是想知道我怎样才能解决这个问题。我希望名称标签位于顶部中间框架的左上角。该
框架_topmiddle
缩小为标签_名称
的大小,默认情况下显示在(第0行,第1列)的中心
如果将网格方法的sticky
选项设置为“nw”:frame\u topmiddle.grid(行=0,列=1,粘性=nw')
然后,frame\u topmiddle
将位于(第0行,第1列)的左上角,而不是中间
如果您希望frame\u topmiddle
保持其初始大小,则需要执行以下操作
frame\u top middle.grid\u propagate(False)