Categories
Mastering Development

Make a button open a Window on Beeware

I’m very new to coding, about 2 weeks in. But, for a school project, I’m trying to create an app. To make my Python run on android, I’m using the Beeware suite. So, what I want to do is, on Android, when I click a button, I want it to open a new window. Like when you’re on instagram and you click on someone’s profile. Here’s the code I’ve done til now.

import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW


def about(button, formal_name='a'):
    main_box = toga.Box(style=Pack(direction=COLUMN, background_color='#7ed6c6'))
    hello = toga.Label('Hello there!')
    main_window = toga.MainWindow(title=formal_name)
    main_window.content = main_box
    main_window.show()
    main_box.add(hello)

class Casa_musica(toga.App):

    def startup(self):
        main_box = toga.Box(style=Pack(direction=COLUMN, background_color='#7ed6c6', padding=20))

        button = toga.Button(
            'Click me', on_press=about)
        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
        main_box.add(button)


def main():
    return Casa_musica()

Leave a Reply

Your email address will not be published. Required fields are marked *