要看到差异,你需要付出tkinter
单元格不完全适合您的小部件的原因,如果可能的话,默认情况下它总是会这样做。尝试:
from tkinter import *
from tkinter import ttk
root = Tk()
root.rowconfigure(0,weight = 1)
root.columnconfigure(0,weight = 1)
frame = ttk.Frame(root)
frame.grid(row = 0,column =0)
ttk.Label(frame,text = 'Label_1',background='red').grid(row=0,column=0,sticky='nwes')
ttk.Button(frame,text = 'Button').grid(row=0,column=1,sticky='nwse')
ttk.Label(frame,text = 'Label``_2').grid(row=0,column=2,sticky='nwes')
ttk.Label(frame,text = 'LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG').grid(row=1,column=0)
root.mainloop()
然后删除,sticky='news'
from Label_1
。请注意,文本居中和小部件居中是两个不同的东西 - 这就是为什么我给出了背景颜色,以使其明显。
另外,你并不真正需要ttk
,你得到你的Button
s and Frame
s from from tkinter import *
已经,尽管我会明确地将它们列出为from tkinter import Button,Frame,Tk
or use import tkinter as tk
并使用tk.Label
.