2016-11-02 6 views
0

私はフレームを持って、それは私がcolumn = 2 & column = 3を持っているしたいテキストHighLowが含まれていること、row = 0です。私はその下に数値を含む行があります。ラベルには幅をすべて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

設定してみてください 'スティッキー=同じ列にラベルの幅を揃えることができます。 – 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

関連する問題