簡體   English   中英

即使寬度相等,為什么我的標簽尺寸不同?

[英]Why are my label different sizes even though the widths are equal?

我有一個位於row = 0的框架,其中包含我想在column = 2column = 3中使用的文本HighLow 我在其下面的另一行包含一個數值。 但是在標簽上,我將寬度設置為全部等於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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM