This is what it looks like when i run it, which is what i want except the flip button does nothing我已经为其他人尝试了许多修复程序,但均未解决,因此我上载了我的工作,希望有人可以帮助我。如果您可以发表评论,但由于我所不具备的知识,您可能必须以最简单的方式进行说明。
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.button import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
class Shark(App):
def build(self):
self.max_food = 50
self.food = self.max_food
self.respect = 0
self.layout = BoxLayout(orientation="vertical")
area1 = BoxLayout(orientation="horizontal")
area2 = BoxLayout(orientation="horizontal")
area3 = BoxLayout(orientation="horizontal")
self.layout.add_widget(area1)
self.layout.add_widget(area2)
self.layout.add_widget(area3)
self.lbl1 = Label(text="{}/{} Food".format(self.food, self.max_food))
self.lbl2 = Label(text="{} Respect".format(self.respect))
area1.add_widget(self.lbl1)
area1.add_widget(self.lbl2)
btn1 = Button(text="Area 1")
btn2 = Button(text="Area 2")
area2.add_widget(btn1)
area2.add_widget(btn2)
btn3 = Button(text="Eat")
btn4 = Button(text="Flip")
btn4.bind(on_press=self.flip)
area3.add_widget(btn3)
area3.add_widget(btn4)
return self.layout
def eat(self):
pass
def flip(self, obj):
self.food -= 10
self.respect += 10
self.lbl1.text="{}/{} Food".format(self.food, self.max_food)
self.lbl2.text="{} Respect".format(self.respect)
Shark().run()
答案 0 :(得分:0)
更改:
btn4.bind(on_push=self.flip)
收件人:
btn4.bind(on_press=self.flip)
我认为on_push无效。