[英]Why are my label different sizes even though the widths are equal?
I have a frame, that is in row = 0
, that contains the text High
and Low
which I would like to have in column = 2
& column = 3
. 我有一个位于
row = 0
的框架,其中包含我想在column = 2
& column = 3
中使用的文本High
和Low
。 I have another row below it that contains a numerical value. 我在其下面的另一行包含一个数值。 however on the label I set the width to all be equal to 7.
但是在标签上,我将宽度设置为全部等于7。
What am I doing wrong here? 我在这里做错了什么?
##Forecast Frame
self.ForecastFrame = Frame(self, bg='black')
self.ForecastFrame.grid(row = 0, column = 0)
##Forecast Title
self.forecastTitle = Frame(self.ForecastFrame, bg='white')
self.forecastTitle.grid(row = 0, column = 0, sticky = E)
self.forecastTitleHighLabel = Label(self.forecastTitle, text='High', font=('HelveticaNeue Light', 12), fg='white', bg='green', width = '7', anchor='center')
self.forecastTitleHighLabel.grid(row = 0, column = 2, sticky = E)
self.forecastTitleLowLabel = Label(self.forecastTitle, text='Low', font=('HelveticaNeue Light', 12), fg='white', bg='blue', width = '7', anchor='center')
self.forecastTitleLowLabel.grid(row = 0, column = 3, sticky = E)
##Forecast One Labels
self.forecastOneDate = ''
self.forecastOneIcon = ''
self.forecastOneHigh = ''
self.forecastOneLow = ''
self.forecastOne = Frame(self.ForecastFrame, bg='black')
self.forecastOne.grid(row = 1, column = 0)
self.forecastOneDateLabel = Label(self.forecastOne, font=('HelveticaNeue Light', 12), fg='white', bg='yellow', width=10, anchor='w')
self.forecastOneDateLabel.grid(row = 0, column = 0, sticky = W)
self.forecastOneIconLabel = Label(self.forecastOne, bg='red', width=50)
self.forecastOneIconLabel.grid(row = 0, column = 1, sticky = W)
self.forecastOneHighLabel = Label(self.forecastOne, font=('HelveticaNeue Light', 12, 'bold'), fg='white', bg='blue', width = '7', anchor='center')
self.forecastOneHighLabel.grid(row = 0, column = 2, sticky = E)
self.forecastOneLowLabel = Label(self.forecastOne, font=('HelveticaNeue Light', 12, 'bold'), fg='white', bg='green', width = '7', anchor='center')
self.forecastOneLowLabel.grid(row = 0, column = 3, sticky = E)
effbot.org: Label effbot.org: 标签
width=
宽度=
The width of the label.
标签的宽度。 If the label displays text, the size is given in text units .
如果标签显示文本,则大小以文本单位给出。 If the label displays an image, the size is given in pixels (or screen units ).
如果标签显示图像,则以像素 (或屏幕单位 )为单位指定尺寸。 If the size is set to 0, or omitted, it is calculated based on the label contents.
如果将大小设置为0或省略,则根据标签内容进行计算。 (width/Width)
(宽度/宽度)
It means width
depends on font size and weight. 这意味着
width
取决于字体大小和粗细。
import tkinter as tk
root = tk.Tk()
l1 = tk.Label(root, text='Hello', width=7, fg='white', bg='blue')
f = ('HelveticaNeue Light', 12)
l2 = tk.Label(root, text='Hello', width=7, fg='white', bg='green', font=f)
f = ('HelveticaNeue Light', 12, 'bold')
l3 = tk.Label(root, text='Hello', width=7, fg='white', bg='red', font=f)
l1.grid()
l2.grid()
l3.grid()
root.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.