2017-12-03 9 views
0

이것은 내 GUI 프로그램에서 내가 문제가있어 누군가가 나를 도울 수 있기를 바란다. 내가 당신이 체크 버튼을 클릭하면, 그것은 텍스트 위젯에 가격을 표시해야한다 할 노력하고있어하지만 난 체크 버튼을 클릭 할 때 나에게 오류 제공 :Python - Tkinter CheckButton 문제

File "E:\Phython\Theater.py", line 147, in update_text if self.matinee_price.get(): AttributeError: 'Checkbutton' object has no attribute 'get'

def matinee_pricing(self): 
    #Purchase Label 
    self.theater_label = tkinter.Label(text='Purchase Theater Seats Here', font=('Verdana', 15, 'bold')) 
    self.theater_label.grid(row=2, column=10) 
    #Checkbutton 
    self.matinee_price = BooleanVar() 
    self.matinee_price = tkinter.Checkbutton(text = '101 \nthru \n105', font=('Verdana', 10), bg='light pink', height=5, width=10,\ 
              variable = self.matinee_price, command = self.update_text) 
    self.matinee_price.grid(row=5, column=9) 

    self.result = tkinter.Text(width=10, height=1, wrap = WORD) 
    self.result.grid(row=20, column=10) 

def update_text(self): 
    price = '' 

    if self.matinee_price.get(): 
     price += '$50' 

    self.result.delete(0.0, END) 
    self.result.insert(0.0, price) 
+0

tkinter를 두 번 가져 오지 마세요. 나쁜 습관입니다. 자세한 내용은 [this] (https://stackoverflow.com/questions/47479965/is-there-a-point-to-import-two-different-ways-in-a-program)를 참조하십시오. – Nae

답변

0

당신을 ' 부울 변수를 확인란 자체로 덮어 씁니다. BoolenaVar의 선언에는 다른 이름이 필요하며 다른 함수는 해당 이름을 확인해야합니다.

또한 체크 박스는 기본적으로 상태를 설명하기 위해 0과 1을 사용합니다. 부울을 사용하려면 onvalueoffvalue을 적절하게 변경해야합니다.

def matinee_pricing(self): 
    # [...] 
    self.matinee_price_var = BooleanVar() # Different name for the variable. 
    self.matinee_price = tkinter.Checkbutton(text = '101 \nthru \n105', font=('Verdana', 10), bg='light pink', height=5, width=10,\ 
              variable = self.matinee_price_var, onvalue=True, offvalue=False, command = self.update_text) 
    # Add onvalue, offvalue to explicitly set boolean states. 
    # [...] 

def update_text(self): 
    price = '' 

    # Use the variable, not the checkbox 
    if self.matinee_price_var.get(): 
     price += '$50' 
    #[...] 

피. 에스. : 브래킷 안에 \를 입력 할 필요가 없습니다. 파이썬은 대괄호 안에있는 모든 것이 앞의 명령의 일부라고 가정합니다.이 경우에는 체크 상자입니다. 구문 오류가 발생하지 않았는지 확인하고 개별 인수를 줄마다 분리하지 마십시오.

+1

'variable = self.matinee_price'를'variable = self.matinee_price_var'로 변경할 필요가 없습니까? – Nae

+0

물론, 나는 그것을 잊어 버렸습니다. 수정해 주셔서 감사합니다. – ikom

+0

감사합니다 !! 이제 잘 작동합니다. 저는 파이썬에 익숙하지 않고 강의하는 것보다 워크숍을 더 많이 사용하기 때문에 인터넷/유튜브 만이 나의 유일한 출처입니다. – IceBuko