![](/img/trans.png)
[英]Why does my Pygame label not show up even though I copied from my other one that worked?
[英]Why are my label different sizes even though the widths are equal?
我有一个位于row = 0
的框架,其中包含我想在column = 2
& column = 3
中使用的文本High
和Low
。 我在其下面的另一行包含一个数值。 但是在标签上,我将宽度设置为全部等于7。
我在这里做错了什么?
##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: 标签
宽度=
标签的宽度。 如果标签显示文本,则大小以文本单位给出。 如果标签显示图像,则以像素 (或屏幕单位 )为单位指定尺寸。 如果将大小设置为0或省略,则根据标签内容进行计算。 (宽度/宽度)
这意味着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.