I´m making a kivy program and I have a button which when it´s pressed a label with a number increseas in 1 but for some reason i can only call the function once. Here is my code:
import kivy
kivy.require("1.11.1")
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
class Contenedor(FloatLayout):
def __init__(self):
super(Contenedor, self).__init__()
self.sumarHora = Button(text = "h", size_hint = (0.15, 0.15), pos_hint = {'x': 0.33, 'y': .775}, on_press = self.masHora)
self.hora = Button(text = "0", size_hint = (0.15, 0.25), pos_hint = {'x': 0.33, 'y': .475})
self.add_widget(self.sumarHora)
self.add_widget(self.hora)
def masHora(self, event):
hora = int(self.hora.text)
hora =+1
if hora >= 24:
hora = 0
self.hora.text = str(hora)
class MainApp(App):
title = "Interfaz Grafica"
def build(self):
return Contenedor()
if __name__ == '__main__':
MainApp().run()
There's a typo in the code:
hora =+1 # hora = 1
should be replaced with
hora += 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.