How to keep the window open in Python Kivy?

Asked

Viewed 53 times

0

I am learning the Python Kivy library. The code is not making mistakes, but the window opens and closes immediately. How can I make the window stay open?

import kivy
from kivy.app import App
from kivy.uix.label import Label

kivy.require('1.9.1')

class PrimeiroApp(App):
    def build(self):
        return Label(text='Hello World, Kivy!')

if __name__ == '__main__':
    PrimeiroApp().run()

2 answers

0

Try this:

from kivy.app import App
from kivy.uix.label import Label

class Texto(Label):
    def __init__(self, **kwargs):
        super(Texto,self).__init__(**kwargs)
        self.text = 'Label'
    
class NameApp(App):
    def build(self):
        return Texto()

NameApp().run()

0

from kivy.app import App
from kivy.uix.label import Label


def build(): # retornar o gratico 3
  return Label(text="Label") # ao iniciada retornara a classe de label


janela = App() # instancia de App 1
janela.build  = build # associando build definida em App a função build criada 3..
janela.run() # iniciando o app:  2

First started a variable called window and assigned to it the App class then started the app with the run function().
The App class has the built-in build function and was linked to the build function created that returns a Label class. using function only.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.