pythonのみ、またはkv言語を使用できます。それはあなた次第です。 この場合、ボタン呼び出し関数を作成し、ラベルテキストをインクリメントします。 私は2つの例を作ります。 1つはPythonのみで、もう1つはKivy言語と組み合わせて使用します。 Pythonとkivy言語を使用して
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
class Game(BoxLayout):
def __init__(self,**kwargs):
super(Game,self).__init__(**kwargs)
self.count = 0
self.orientation = "vertical"
self.button = Button(on_press=self.increment, text="Increment")
self.label = Label(text="0")
self.add_widget(self.button)
self.add_widget(self.label)
def increment(self,*args):
self.count += 1
self.label.text = str(self.count)
class MyApp(App):
def build(self):
return Game()
、同じアプリ:
は、これが唯一のpythonの例です。
Pythonのファイル:
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
class Game(BoxLayout):
label_text = StringProperty()
def __init__(self,**kwargs):
super(Game,self).__init__(**kwargs)
self.count = 0
self.label_text = str(self.count)
def increment(self,*args):
self.count += 1
self.label_text = str(self.count)
print self.label_text
class MyApp(App):
def build(self):
return Game()
MyApp().run()
そしてmy.kvファイル:
#:kivy 1.9.1
<Game>:
orientation: "vertical"
Button:
text: "Increment"
on_press: root.increment()
Label:
text: root.label_text