python,kivyを用いて画面下部のボタンを押すと表示されるテキストに'X'が追加されるというプログラムを書きました。
実行したところ変数内のテキスト上には'X'が追加されたことが確認できましたが、実際のGUIの表示が変化しません。
このプログラムの間違えているところ、StringProperty以外を用いて上記の機能を実装する方法をご教示いただけますと幸いです。
よろしくお願いします。
python
1from kivy.app import App 2from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition 3from kivy.properties import StringProperty 4 5sm = ScreenManager(transition=NoTransition()) 6 7class GuiTest3(App): 8 9 def build(self): 10 sm.add_widget(Main(name='Main')) 11 return sm 12 13 14class Main(Screen): 15 16 image = StringProperty() 17 image = 'ABC' 18 19 def test(self): 20 self.image = self.image + "X" 21 print(self.image) 22 23if __name__ == '__main__': 24 GuiTest3().run()
guitest3.kv
guitest3
1<Main>: 2 BoxLayout: 3 orientation: "vertical" 4 canvas.before: 5 Color: 6 rgba: 0.07, 0.5, 0.3, 1 7 Rectangle: 8 pos: self.pos 9 size: self.size 10 11 Label: 12 text: root.image 13 font_size: 20 14 color: 1, 1, 1, 1 15 16 Button: 17 size_hint: 1, 0.6 18 pos: 0, 0 19 color: 1, 1, 1, 1 20 text: root.image 21 font_size: 20 22 on_press: root.test() 23
使用環境
Python 3.6.4
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。