2016-09-23 4 views
-2

기존 질문을 살펴 보았지만 지금까지 해결 방법을 찾을 수 없었습니다.'NoneType'개체에 '__getitem__'속성이 없습니다. - Tkinter

저는 파이썬 프로그래밍 언어에 익숙하지 않고 Tk로 놀기 시작했으나 체크 박스에서 값을 가져 오거나 레이블 값을 변경하려고 할 때 다음과 같은 오류 메시지가 계속 나타납니다.

'NoneType'개체가 어떤 속성 아래

가 버튼

from Tkinter import * 

the_window = Tk() 

the_window.title('Button Change Colour') 

def change_to_red(): 
    colour_area['text']='Red' 

colour_area = Label(the_window, bg='Grey', text = 'test', width = 40, height = 5).grid(row = 1, column = 1, padx = 5, pady = 5) 
red_button = Button(the_window, text='Red', width = 5, command = change_to_red).grid(row = 2, column = 1) 

the_window.mainloop() 

을 클릭하면 나는 오류가 발생하는 내 코드의 예입니다 '의 getItem을'이없는 나는 확신 작거나 바보 같지만, 그럼에도 불구하고 당신의 도움을 주셔서 감사합니다! :)

+0

@AndrewL. 그래, 맞아. 당연히 그래. ^^ 그건 연상 될거야. –

답변

1

혼란 스럽긴하지만 colour_area을 레이블로 선언하지 않았다면 방금 표에 추가했습니다.

from Tkinter import * 

the_window = Tk() 

the_window.title('Button Change Colour') 

def change_to_red(): 
    colour_area['text']='Red' 

# initializing colour_area as a Tk.Label 
colour_area = Label(the_window, bg='Grey', text = 'test', width = 40, height = 5) 
# adding it to the grid 
colour_area.grid(row = 1, column = 1, padx = 5, pady = 5) 
red_button = Button(the_window, text='Red', width = 5, command = change_to_red).grid(row = 2, column = 1) 

the_window.mainloop() 

이 제대로 작동합니다
여기에 오류가 있습니다.

+0

완벽하게 작동합니다! 고맙습니다! 그래서, 모든 문제는 내가 동일한 것을 포장하거나 그리드하려고하기 때문에 발생합니다. 말이된다! –

+0

@DominicFichera 당신은 아주 잘 할 수 있지만 한 번만 할 수 있습니다. * 나중에 * 위젯에 액세스하거나 구성하거나 얻을 필요가있는 경우 * 아닙니다 *. –

관련 문제