Events passing in python with kivy -
i new python , kivy, trying clear widgets in host when button pressed, code follows:
from kivy.uix.button import button kivy.uix.gridlayout import gridlayout kivy.uix.boxlayout import boxlayout kivy.uix.popup import popup kivy.uix.label import label spots={} class spot(button): ''' classdocs ''' def __init__(self, **kwargs): ''' constructor ''' super(spot,self).__init__(**kwargs) self.ismine=false if 'text' in kwargs: self.text=kwargs['text'] else: self.text="x" def on_press(self, *args, **kwargs): #return button.on_press(self, *args, **kwargs) game.spottouched(self, self.text) class game(boxlayout): def __init__(self,**kwargs): super(game,self).__init__(**kwargs) self.m=minesholder(rows=25, cols=25) self.add_widget(self.m) self.attachtogrid() def attachtogrid(self): self.m.clear_widgets() spots.clear() r in range(0,25): c in range(0,25): idd=str(r)+","+str(c) spots[idd]=idd self.m.add_widget(spot(text=idd)) def spottouched(self,spotid): #popup=popup(title=spotid) #popup.open() self.clear_widgets()
the last line clearing widgets, , spot class has on_press event. trying pass event of on_press of button on app holding boxlayout (game class), please tell/point me in right direction lean on how pass events?
thank you.
i think want, based on comment on @inclement's answer: rid of on_press
method on button. want bind event instead - work more wpf.
for r in range(0,25): c in range(0,25): idd=str(r)+","+str(c) spots[idd]=idd s = spot(text=idd) self.m.add_widget(s) s.bind(on_press=self.spottouched)
so self.spottouched
event handler spot
s on_press
event.
s.bind(on_press=self.spottouched)
is kind of this:
addhandler s.click, addressof spottouched
note adding handler way, handler receive single argument spot
instance. can spot.text
instance.
Comments
Post a Comment