Convert Figma logo to code with AI

beeware logotoga

A Python native, OS native GUI toolkit.

4,407
685
4,407
247

Top Related Projects

17,941

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS

2,346

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.

Python GUIs for Humans! PySimpleGUI is the top-rated Python application development environment. Launched in 2018 and actively developed, maintained, and supported in 2024. Transforms tkinter, Qt, WxPython, and Remi into a simple, intuitive, and fun experience for both hobbyists and expert users.

11,752

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.

6,736

PyQt Examples(PyQt各种测试和例子) PyQt4 PyQt5

Quick Overview

Toga is a Python native, OS native GUI toolkit that allows developers to create desktop applications with a native look and feel across multiple platforms. It's part of the BeeWare project, aiming to write native mobile and desktop applications in Python.

Pros

  • Cross-platform compatibility (Windows, macOS, Linux, iOS, Android)
  • Native look and feel on each platform
  • Integrates well with other BeeWare tools
  • Pure Python implementation, making it easy for Python developers to adopt

Cons

  • Still in beta, with some features missing or incomplete
  • Smaller community and ecosystem compared to more established GUI frameworks
  • Documentation can be sparse in some areas
  • Performance may not be as optimized as some platform-specific frameworks

Code Examples

  1. Creating a simple button:
import toga

def button_handler(widget):
    print("Hello, World!")

button = toga.Button('Hello World', on_press=button_handler)
  1. Creating a basic app with a box layout:
import toga

class ExampleApp(toga.App):
    def startup(self):
        main_box = toga.Box(style=Pack(direction=COLUMN))
        
        name_label = toga.Label('Your name: ')
        self.name_input = toga.TextInput()
        
        button = toga.Button('Say Hello!', on_press=self.say_hello)
        
        main_box.add(name_label)
        main_box.add(self.name_input)
        main_box.add(button)
        
        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()

    def say_hello(self, widget):
        print(f"Hello, {self.name_input.value}!")

def main():
    return ExampleApp('Example App', 'org.example.exampleapp')
  1. Adding an image to your app:
import toga
from toga.style import Pack

image = toga.Image('path/to/image.png')
image_view = toga.ImageView(image)
box.add(image_view)

Getting Started

To get started with Toga, follow these steps:

  1. Install Toga:

    pip install toga
    
  2. Create a new Python file (e.g., app.py) and import Toga:

    import toga
    
  3. Define your app class:

    class MyApp(toga.App):
        def startup(self):
            self.main_window = toga.MainWindow(title=self.name)
            self.main_window.show()
    
    def main():
        return MyApp('My App', 'org.example.myapp')
    
    if __name__ == '__main__':
        main().main_loop()
    
  4. Run your app:

    python app.py
    

This will create a basic Toga application with a main window. You can then add widgets and customize your app as needed.

Competitor Comparisons

17,941

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS

Pros of Kivy

  • More mature and established project with a larger community
  • Extensive documentation and learning resources available
  • Supports multi-touch events and gestures out of the box

Cons of Kivy

  • Steeper learning curve due to its custom widget system
  • Non-native look and feel across platforms
  • Larger app size due to bundled dependencies

Code Comparison

Kivy:

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

class MyApp(App):
    def build(self):
        return Button(text='Hello World')

MyApp().run()

Toga:

import toga

def build(app):
    return toga.Button('Hello World')

app = toga.App('First App', 'org.example.first', startup=build)
app.main_loop()

Summary

Kivy is a more established project with extensive documentation and support for advanced touch interactions. However, it has a steeper learning curve and produces non-native looking apps. Toga, part of the BeeWare project, aims for a more native look and feel but is less mature. The code comparison shows that both frameworks offer simple ways to create basic UI elements, with Kivy using a class-based approach and Toga using a function-based structure.

2,346

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.

Pros of Phoenix

  • Mature and well-established framework with a large user base and extensive documentation
  • Supports a wide range of native widgets and controls across multiple platforms
  • Offers more fine-grained control over UI elements and layouts

Cons of Phoenix

  • Steeper learning curve compared to Toga's simpler API
  • Requires more boilerplate code for basic applications
  • Less focus on modern, mobile-first design patterns

Code Comparison

Phoenix:

import wx

app = wx.App()
frame = wx.Frame(None, title="Hello World")
frame.Show()
app.MainLoop()

Toga:

import toga

def build(app):
    box = toga.Box()
    return box

app = toga.App("Hello World", "org.example.hello", startup=build)
app.main_loop()

Summary

Phoenix offers a more comprehensive and mature toolkit for desktop applications, with greater control over UI elements. Toga, on the other hand, provides a simpler API and focuses on cross-platform compatibility, including mobile platforms. Phoenix is better suited for complex desktop applications, while Toga excels in creating lightweight, multi-platform apps with a consistent look and feel.

Python GUIs for Humans! PySimpleGUI is the top-rated Python application development environment. Launched in 2018 and actively developed, maintained, and supported in 2024. Transforms tkinter, Qt, WxPython, and Remi into a simple, intuitive, and fun experience for both hobbyists and expert users.

Pros of PySimpleGUI

  • Simpler syntax and easier to learn for beginners
  • Extensive documentation and examples
  • Supports multiple GUI frameworks (tkinter, Qt, WxPython, Remi)

Cons of PySimpleGUI

  • Less native look and feel across platforms
  • Limited customization options for complex UI designs
  • May have performance issues with large-scale applications

Code Comparison

PySimpleGUI:

import PySimpleGUI as sg

layout = [[sg.Text("Hello World!")], [sg.Button("OK")]]
window = sg.Window("Demo", layout)

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED or event == "OK":
        break

window.close()

Toga:

import toga

def button_handler(widget):
    print("Hello, World!")

def build(app):
    box = toga.Box()
    button = toga.Button("Hello World!", on_press=button_handler)
    box.add(button)
    return box

if __name__ == "__main__":
    app = toga.App("First App", "org.example.first", startup=build)
    app.main_loop()

PySimpleGUI offers a more concise syntax for simple applications, while Toga provides a more object-oriented approach with better support for native UI elements across different platforms.

11,752

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.

Pros of Flet

  • Simpler syntax and faster development, especially for Python developers
  • Built-in state management and reactive UI updates
  • Supports web deployment out of the box

Cons of Flet

  • Less native look and feel compared to Toga
  • Limited to Flutter-based widgets, which may not cover all native UI elements
  • Newer project with potentially less stability and community support

Code Comparison

Flet example:

import flet as ft

def main(page: ft.Page):
    page.add(ft.Text("Hello, World!"))

ft.app(target=main)

Toga example:

import toga

def build(app):
    box = toga.Box()
    box.add(toga.Label("Hello, World!"))
    return box

if __name__ == '__main__':
    app = toga.App("First App", "org.example.first", startup=build)
    app.main_loop()

Both Flet and Toga aim to simplify cross-platform GUI development in Python, but they take different approaches. Flet focuses on rapid development with a Flutter-based UI, while Toga emphasizes native look and feel across platforms. Flet's syntax is generally more concise and reactive, making it easier for quick prototyping. However, Toga offers better integration with native UI elements and potentially better performance on desktop platforms. The choice between the two depends on the specific requirements of your project and the desired balance between development speed and native platform integration.

6,736

PyQt Examples(PyQt各种测试和例子) PyQt4 PyQt5

Pros of PyQt

  • Mature and feature-rich framework with extensive documentation
  • Excellent integration with Qt Designer for GUI layout
  • Wide range of widgets and tools for complex applications

Cons of PyQt

  • Licensing can be complex and potentially costly for commercial use
  • Larger application size due to Qt dependencies
  • Steeper learning curve, especially for those new to Qt concepts

Code Comparison

PyQt5 example:

from PyQt5.QtWidgets import QApplication, QLabel
app = QApplication([])
label = QLabel("Hello World!")
label.show()
app.exec_()

Toga example:

import toga
def build(app):
    box = toga.Box()
    box.add(toga.Label("Hello World!"))
    return box
app = toga.App("First App", "org.example.first", startup=build)
app.main_loop()

Both examples create a simple "Hello World" application, but Toga's approach is more declarative and follows a different structure compared to PyQt5's event-driven model. PyQt5 offers more direct control over widgets, while Toga abstracts some of these details for cross-platform compatibility.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

.. |logo| image:: https://beeware.org/project/projects/libraries/toga/toga.png :width: 72px :target: https://beeware.org/toga

.. |pyversions| image:: https://img.shields.io/pypi/pyversions/toga.svg :target: https://pypi.python.org/pypi/toga :alt: Python Versions

.. |version| image:: https://img.shields.io/pypi/v/toga.svg :target: https://pypi.python.org/pypi/toga :alt: Project version

.. |maturity| image:: https://img.shields.io/pypi/status/toga.svg :target: https://pypi.python.org/pypi/toga :alt: Project status

.. |license| image:: https://img.shields.io/pypi/l/toga.svg :target: https://github.com/beeware/toga/blob/main/LICENSE :alt: BSD License

.. |ci| image:: https://github.com/beeware/toga/workflows/CI/badge.svg?branch=main :target: https://github.com/beeware/toga/actions :alt: Build Status

.. |social| image:: https://img.shields.io/discord/836455665257021440?label=Discord%20Chat&logo=discord&style=plastic :target: https://beeware.org/bee/chat/ :alt: Discord server

|logo|

Toga

|pyversions| |version| |maturity| |license| |ci| |social|

A Python native, OS native GUI toolkit.

Minimum requirements

  • Toga requires Python 3.9 or higher.

  • If you're on macOS, you need to be on 11 (Big Sur) or newer.

  • If you're on Windows, you'll need Windows 10 or newer. If you are using Windows 10 and want to use a WebView to display web content, you will also need to install the Edge WebView2 Evergreen Runtime <https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section>__. Windows 11 has this runtime installed by default.

  • If you're on Linux (or another Unix-based operating system), you need to have GTK+ >= 3.24 and glib >= 2.64. These are available starting with Ubuntu 20.04 and Fedora 32. You also need to install the system packages listed in Linux platform documentation <https://toga.readthedocs.io/en/latest/reference/platforms/linux.html#prerequisites>__.

Quickstart

To get a demonstration of the capabilities of Toga, run the following::

$ pip install toga-demo
$ toga-demo

This will pop up a GUI window with some sample widgets.

Documentation

Documentation for Toga can be found on Read The Docs_.

.. _Read The Docs: https://toga.readthedocs.io

Community

Toga is part of the BeeWare suite_. You can talk to the community through:

  • @beeware@fosstodon.org on Mastodon_
  • Discord_
  • The Toga Github Discussions forum_

We foster a welcoming and respectful community as described in our BeeWare Community Code of Conduct_.

.. _BeeWare suite: https://beeware.org .. _@beeware@fosstodon.org on Mastodon: https://fosstodon.org/@beeware .. _Discord: https://beeware.org/bee/chat/ .. _Github Discussions forum: https://github.com/beeware/toga/discussions .. _BeeWare Community Code of Conduct: https://beeware.org/community/behavior/

Contributing

If you'd like to contribute to Toga development, our guide for first time contributors_ will help you get started.

If you experience problems with Toga, log them on GitHub. If you want to contribute code, please fork the code and submit a pull request_.

.. _guide for first time contributors: https://toga.readthedocs.io/en/latest/how-to/contribute/index.html .. _log them on Github: https://github.com/beeware/toga/issues .. _fork the code: https://github.com/beeware/toga .. _submit a pull request: https://github.com/beeware/toga/pulls