Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:16:47+00:00 2026-06-18T10:16:47+00:00

I am using the Kivy python library. I have two widgets defined. When the

  • 0

I am using the Kivy python library.

I have two widgets defined.

When the program runs, I run the first widget.

When that widgets button is pressed, I want it to dissapear and be replaced with the second widget.

Here is the .kv for the two widgets

#uitest.kv
<TestForm>:
    canvas:
        Rectangle:
            pos: self.center_x, 0
            size: 10, self.height

    BoxLayout:
        size: root.size
        padding: 40
        Button:
            text: 'Hello'
            on_release: root.testCallback()

<TestForm2>:
    canvas:
        Rectangle:
            pos: self.center_x, 0
            size: self.height, 10

My main python file runs the app, and returns the first widget

#main.py
from testform import TestForm
from kivy.app import App

class UITestApp(App):
    def build(self):
        return TestForm()

# Main launching point
if __name__ in ('__main__', '__android__'):
    UITestApp().run()

My first widget has a callback. This is where the code-in-question belongs

from testform2 import TestForm2
from kivy.uix.widget import Widget

class TestForm(Widget):
    def testCallback(self):
        TestForm2() # Code in question goes here. @TODO replace this widget with TestForm2 widget.

The idea here is to have a user interface manager. This manager doesn’t run the UI like a tree, but like a list and stack. The list holds instances of all my UI Forms. The stack holds the traversal of said forms, whenever we jump to a form we push it to the stack and “render” or whatever that one.

EDIT:
I chose my answer, but in my searches I also found the Screen object: http://kivy.org/docs/api-kivy.uix.screenmanager.html
Personally, the clear() and add() commands are more powerful, but the screen takes a lot of that out of your hands if you’re interested. Transition effects too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:16:48+00:00Added an answer on June 18, 2026 at 10:16 am

    My suggestion is to have an interface manager widget, then you can have various widgets for your UI forms.

    import kivy
    from kivy.uix.label import Label
    from kivy.uix.button import Button
    from kivy.uix.boxlayout import BoxLayout
    from kivy.app import App
    
    class InterfaceManager(BoxLayout):
    
        def __init__(self, **kwargs):
            super(InterfaceManager, self).__init__(**kwargs)
    
            self.first = Button(text="First")
            self.first.bind(on_press=self.show_second)
    
            self.second = Button(text="Second")
            self.second.bind(on_press=self.show_final)
    
            self.final = Label(text="Hello World")
            self.add_widget(self.first)
    
        def show_second(self, button):
            self.clear_widgets()
            self.add_widget(self.second)
    
        def show_final(self, button):
            self.clear_widgets()
            self.add_widget(self.final)
    
    
    class MyApp(App):
        def build(self):
            return InterfaceManager(orientation='vertical')
    
    if __name__ == '__main__':
        MyApp().run()
    

    You wouldn’t structure it like that of course. You could hold all your forms in a dictionary on the Container object and have a universal callback which provides another form by key.

    class InterfaceManager(BoxLayout):
    
        def __init__(self, **kwargs):
            super(InterfaceManager, self).__init__(**kwargs)
            self.forms = {}
    
        def add_form(self, key, form):
            self.forms[key] = form
    
        def uniCallback(self, button):
            self.clear_widgets()
            # You could introduce a more elegant key
            # handling system here.
            self.add_widget(self.forms[button.text])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the Kivy library for python in the Eclipse IDE.
I've noticed that when you make buttons using the grid layout in Kivy they
Using SSRS 2008 R2 I have a background process that dynamically generates RDL for
Using CRM 4, I have an entity form that contains a tab with an
Using ember 1.0.0-pre3 I have a little app that has this code: window.App =
Using CI for the first time and i'm smashing my head with this seemingly
Using import datetime in python, is it possible to take a formatted time/date string
I'm writing a custom widget for kivy(see this question), but I just found out
Using getDefinitionByName I am consistently getting the error saying it is not defined (as
Using Trigger.io's barcode api in an application that only contains boilerplate HTML and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.