from kivy.uix.image import Image from kivy.base import runTouchApp as app class Imager(Image): def on_touch_down(self, touch): print(touch.button) app(Imager(source='java.png'))
if self.parent: Window.bind(mouse_pos=self.on_mouse_move) else: Window.unbind(mouse_pos=self.on_mouse_move) def on_mouse_move(self, win, pos): if self.collide_point(*self.to_widget(*pos)): self.hover = True else: self.hover = False if __name__ == "__main__": from kivy.base import runTouchApp as app from kivy.uix.button import Button from kivy.uix.boxlayout import BoxLayout class HoverButton(HoverBehavior, Button): def on_hover(self, *args): if self.is_hover: self.text = 'Yeah!!' else: self.text = '' box = BoxLayout() box.add_widget(HoverButton()) box.add_widget(Button(text='Hello')) app(box)
class AndriodTabScreen(ScreenScatter): @property def set_pos(self): if self.orientation == 'landscape': return (-self.container.height - 35, -dp(51)) return (-dp(35), -dp(51)) @property def set_size(self): return (self.width + dp(70), self.height + dp(102)) class AndroidPhoneScreen(ScreenScatter): @property def set_pos(self): if self.orientation == 'landscape': return (-self.container.height - 16.5, -dp(85.5)) return (-dp(16.5), -dp(85.5)) @property def set_size(self): return (self.container.width + dp(32), self.container.height + dp(152)) Builder.load_file('screen.kv') if __name__ == "__main__": app(build)
app( Builder.load_string(''' BoxLayout: Carousel: canvas.before: Color: rgba: 1,1,1,1 Rectangle: size: self.size pos: self.pos FloatLayout: IpadScreen: on_scale: self.center=root.center center: root.center id: screen Button: text: 'Hello' font_size: '17dp' BoxLayout: pos_hint: {'y': .01, 'center_x': .5} size_hint: None,None size: '120dp', '60dp' Button: text: '-' bold: True on_release: if not screen.scale < -100.0: screen.scale -= 0.05 Button: text: '+' bold: True on_release: screen.scale += 0.05 # Carousel: # AndroidPhoneScreen: # Button: # text: 'Hello' # IphoneScreen: # Button: # text: 'Hello' # IpadScreen: # Button: # text: 'Hello' # AndriodTabScreen: # Button: # text: 'Hello' '''))
rgba: 0,0,0,1 Rectangle: texture: self.texture size: self.texture_size pos: self.center_x-self.texture_size[0]/2, self.center_y-self.texture_size[1]/2 PopMatrix: ''') if __name__ == '__main__': grid = Builder.load_string(''' GridLayout: size_hint_y: None height: self.minimum_height cols: 1 ''') class Reloader(ReloadBehavior, ScrollView): def on_reload(self): # do anythin print('Reloading........') reloader = Reloader() reloader.add_widget(grid) for i in range(20): grid.add_widget( Button(size_hint_y=None, text=str(i + 1), height='46dp')) app(reloader)