How do I add and remove wigdets dynamically?

1
import kivy
kivy.require('1.10.1')

from kivy.app import App  
from kivy.uix.boxlayout import BoxLayout  
from kivy.uix.button import Button  

class Tela-1 (BoxLayout):

    def on_press_bt(self):
        janela.root_window.remove_wigdet(janela.root)
        janela.root_window.add_wigdet(Tela2())

    def __init__(self, **kwargs):
        super(Tela1, self).__init__(**kwargs)
        self.orientation = 'vertical'
        bt1 = Button(text='Click')
        bt1.on_press = self.on_press_bt
        self.add_widget(bt1)
        self.add_widget(Button(text='bt2'))
        self.add_widget(Button(text='bt3'))

class Tela-2 (BoxLayout):

    def on_press_bt(self):
        janela.root_window.remove_wigdet(janela.root)
        janela.root_window.add_wigdet(Tela1())

    def __init__(self, **kwargs):
        super(Tela2, **kwargs).__init__(**kwargs)
        self.orientation = 'vertical'
        bt = Button(text='Click')
        bt.on_press = self.on_press_bt
        self.add_widget(bt)  

class Principal(App):


    def build(self):  
        return Tela1()
janela = Principal()  
janela.run()
    
asked by anonymous 25.08.2018 / 16:45

0 answers