2016-11-02 1 views
0

내가 프레임을 가지고, 그 row = 0에, 그게 내가 column = 2 & column = 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) 
+0

읽어 보시기 바랍니다 (http://www.stackoverflow.com/help/mcve) (MCVE) [A, 최소 완료하고 검증 가능한 예제를 만드는 방법] –

+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

관련 문제