-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()
동일한 개체에 대한 메서드이기 때문에'self.update()'를 사용해보십시오. – jonrsharpe
클래스가 새 범위를 정의하지 않습니다. 'update'가'on_touch_down' 내에 로컬로 정의되어 있지 않기 때문에, 그 다음으로 이름을 찾는 곳은'class (클래스)의 본문이 아니라 전역 범위 (또는 더 구체적으로'childWidget'가 정의 된 범위)입니다. '진술. – chepner
@jonrcharpe 내가 할 때 나는 오류가 발생합니다 : update() 0 위치 인수를하지만 1 주어집니다. – Flower