2017-10-15 1 views
-1

저는 python으로 kivy 응용 프로그램을 작성하고 있습니다. 동일한 위젯 (update 및 on_touch_down)에서 두 개의 함수를 정의했습니다. 내장 된 "on_touch_down"함수 인 두 번째 함수는 첫 번째 함수를 호출합니다. 사용자가 화면을 클릭하면 첫 번째 기능을 호출하는 것이 좋습니다. 나는 응용 프로그램을 실행하고 화면을 클릭하면 그러나, 오류가 나타납니다이름 오류 : 함수가 정의되지 않은 이유는 무엇입니까?

class childWidget(Widget): 
    def update(): 
     for s in range(len(root.markers)): 
      root.map.remove_marker(root.marker[s]) 
     root.markers.clear() 
     cursor.execute("SELECT * FROM aircraft;") 
     new_table = cursor.fetchall() 

     for row in new_table(): 
      markers.append(MapMarker(lon= row[2], lat=row[1], source='if_plane-b_86362.png')) 
      root.map.add_marker(MapMarker(lon= row[2], lat=row[1], source='if_plane-b_86362.png')) 

    def on_touch_down(self,touch): 
     update() 
+2

동일한 개체에 대한 메서드이기 때문에'self.update()'를 사용해보십시오. – jonrsharpe

+2

클래스가 새 범위를 정의하지 않습니다. 'update'가'on_touch_down' 내에 로컬로 정의되어 있지 않기 때문에, 그 다음으로 이름을 찾는 곳은'class (클래스)의 본문이 아니라 전역 범위 (또는 더 구체적으로'childWidget'가 정의 된 범위)입니다. '진술. – chepner

+0

@jonrcharpe 내가 할 때 나는 오류가 발생합니다 : update() 0 위치 인수를하지만 1 주어집니다. – Flower

답변

1

다음과 같은 라인을 변경해야합니다 :

여기

File : "main.py", line 57, in on_touch_down 
    update() 
NameError: name 'update' is not defined 

을 그리고 코드는 문제를 일으키는

라인 2 업데이트() 메서드를 만들 : 당신이 메서드를 호출 할 때

def update(self): 

라인 (14) :

self.update() 
관련 문제