简体   繁体   English

即使宽度相等,为什么我的标签尺寸不同?

[英]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 = 2column = 3中使用的文本HighLow 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.

相关问题 为什么我的 Pygame 标签不显示,即使我从另一个有效的标签中复制? - Why does my Pygame label not show up even though I copied from my other one that worked? 即使概率相等,我的数据仍呈下降趋势 - My Data keeps trending downwards even though it's equal probabilities 我的崇高文本在 python 方法中以不同的颜色显示“自我”,即使它不是保留关键字。 为什么? - My sublime text shows 'self' in python methods in a different color even though it is not a reserved keyword. Why? 为什么我的子弹不动,即使我的坦克 - why are my bullets not moving even though my tanks are Ray 集群中的池将相同数量的作业发送到不同的节点,即使节点具有不同的大小/不同数量的 CPU - Pool in a Ray cluster is sending the same number of jobs to different nodes even though the nodes have different sizes/different number of CPUs 绘制具有恒定条宽但不同 bin 大小的直方图 - Plot a histogram with constant bar widths but different bin sizes 为什么即使在我的路上,点子仍然无法识别? - Why is pip still not recognized even though it is on my path? 为什么即使保存了我的python脚本也没有更新? - Why are my python scripts not updating even though that are saved? 即使我有条件,为什么我的点会进入墙上? - Why are my dots going into the wall even though I have a condition? 为什么即使我添加了一种重新启动它的方法,我的代码也会结束 - Why my code ends even though i add a way to restart it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM