開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
- Kivy (パッケージ)
Kivyプログラミング ―Pythonで作るマルチタッチアプリ― (実践Pythonライブラリー) (原口 和也(著)、久保 幹雄(監修)、朝倉書店)の3(イベントとプロパティ)、3.4(演習問題)、演習3.4の解答を求めてみる。
コード
Python 3
#!/usr/bin/env python3 from kivy.app import App from kivy.uix.button import Button from kivy.uix.floatlayout import FloatLayout from kivy.core.text import LabelBase, DEFAULT_FONT LabelBase.register(DEFAULT_FONT, 'NotoSansCJKjp-Regular.otf') class MyFloatLayout(FloatLayout): def __init__(self, *args, **kwargs): FloatLayout.__init__(self, *args, *kwargs) self.no = 1 def on_touch_down(self, touch): print(f'{touch} ({self.no})') self.add_widget(Button(text=f'タッチ! ({self.no})', size_hint=[0.2, 0.2], center=touch.pos)) self.no += 1 class SampleApp(App): def build(self): float_layout = MyFloatLayout() return float_layout if __name__ == '__main__': SampleApp().run()
入出力結果(Terminal, cmd(コマンドプロンプト), Jupyter(IPython))
$ python3 sample4.py [INFO ] [Logger ] Record log in /~... [INFO ] [Kivy ] v1.10.1 [INFO ] [Python ] v3.7.1 (default, Oct 21 2018, 09:01:26) [Clang 10.0.0 (clang-1000.11.45.2)] [INFO ] [Factory ] 194 symbols loaded [INFO ] [Image ] Providers: img_tex, img_imageio, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored) [INFO ] [Text ] Provider: sdl2 [INFO ] [Window ] Provider: sdl2 [INFO ] [GL ] Using the "OpenGL ES 2" graphics system [INFO ] [GL ] Backend used <gl> [INFO ] [GL ] OpenGL version <b'2.1 INTEL-12.4.7'> [INFO ] [GL ] OpenGL vendor <b'Intel Inc.'> [INFO ] [GL ] OpenGL renderer <b'Intel(R) Iris(TM) Pro Graphics 6200'> [INFO ] [GL ] OpenGL parsed version: 2, 1 [INFO ] [GL ] Shading version <b'1.20'> [INFO ] [GL ] Texture max size <16384> [INFO ] [GL ] Texture max units <16> [INFO ] [Window ] auto add sdl2 input provider [INFO ] [Window ] virtual keyboard not allowed, single mode, not docked [INFO ] [Base ] Start application main loop <MouseMotionEvent spos=(0.5025, 0.6066666666666667) pos=(803.9999999999999, 728.0)> (1) [INFO ] [GL ] NPOT texture support is available <MouseMotionEvent spos=(0.49875, 0.87) pos=(798.0, 1044.0)> (2) <MouseMotionEvent spos=(0.8425, 0.6216666666666666) pos=(1348.0, 745.9999999999999)> (3) <MouseMotionEvent spos=(0.8875, 0.5083333333333333) pos=(1420.0, 610.0)> (4) <MouseMotionEvent spos=(0.935, 0.07166666666666666) pos=(1496.0, 85.99999999999999)> (5) <MouseMotionEvent spos=(0.455, 0.02833333333333332) pos=(728.0, 33.999999999999986)> (6) <MouseMotionEvent spos=(0.09875, 0.08999999999999997) pos=(158.0, 107.99999999999996)> (7) <MouseMotionEvent spos=(0.0275, 0.5166666666666666) pos=(44.0, 619.9999999999999)> (8) <MouseMotionEvent spos=(0.0325, 0.97) pos=(52.0, 1164.0)> (9) <MouseMotionEvent spos=(0.28, 0.7683333333333333) pos=(448.00000000000006, 922.0)> (10) <MouseMotionEvent spos=(0.43125, 0.39) pos=(690.0, 468.0)> (11) [INFO ] [Base ] Leaving application in progress... $
0 コメント:
コメントを投稿