2016-11-02 78 views
0

我有一個框架,即在row = 0,其中包含文本HighLow我想在column = 2 & column = 3。我在它下面有另一行,它包含一個數值。但是在標籤上,我將寬度設置爲全部等於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) 
+0

請閱讀[如何創建一個最小的,完整的,並且可驗證示例](http://www.stackoverflow.com/help/mcve)(MCVE) –

+0

嘗試設置'粘= EW'將標籤的寬度對齊在同一列中。 – acw1668

回答

1

effbot.org:Label

寬度=

標籤的寬度。如果標籤顯示文字,尺寸在文本單位中給出。如果標籤顯示圖像,則尺寸在像素(或屏幕單元)中給出。如果大小設置爲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() 

enter image description here

相關問題