python toga что это

toga 0.2.15

pip install toga Copy PIP instructions

Released: Aug 14, 2017

A Python native, OS native GUI toolkit.

Navigation

Project links

Statistics

View statistics for this project via Libraries.io, or by using our public dataset on Google BigQuery

License: BSD License (New BSD)

Maintainers

Classifiers

Project description

A Python native, OS native GUI toolkit.

* Toga requires **Python 3**. Python 2 is not supported.

* If you’re on macOS, you need to be on 10.7 (Lion) or newer.

* If you’re on Linux, you need to have GTK+ 3.10 or later. This is the version
that ships starting with Ubuntu 14.04 and Fedora 20. You also need to install
the Python 3 bindings to GTK+.

If you want to use the WebView widget, you’ll
also need to have WebKit, plus the GI bindings to WebKit installed. This means
you’ll need to install the following:
* **Ubuntu 14.04** «apt-get install python3-gi gir1.2-webkit-3.0«

* **Ubuntu 16.04 / Debian 8** «apt-get install python3-gi gir1.2-webkit2-4.0«
or «apt-get install python3-gi gir1.2-webkit-3.0«

* **Fedora** «dnf install python3-gobject pywebkitgtk«
or «yum install python3-gobject pywebkitgtk«

Other distros should be similar, but feel free to send a pull request with updated dependencies if needed.

If these requirements aren’t met, Toga either won’t work at all, or won’t have
full functionality.

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 for Toga can be found on `Read The Docs`_.

Toga is part of the `BeeWare suite`_. You can talk to the community through:

* `@pybeeware on Twitter`_

* The `pybee/general`_ channel on Gitter.

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`_.

Источник

Your first Toga appВ¶

Toga is a work in progress, and may not be consistent across all platforms.

Please check the Tutorial Issues label on Github to see what’s currently broken.

In this example, we’re going to build a desktop app with a single button, that prints to the console when you press the button.

Set up your development environmentВ¶

Make sure you installed the Toga prerequisites, such as Python 3 and the other libraries. Then create a working directory for your code and change to it.

If Python 3 is not installed, you can do so via the official installer, or via pyenv, as described in the environment page.

The recommended way of setting up your development environment for Toga is to install a virtual environment, install the required dependencies and start coding. To set up a virtual environment, run:

Your prompt should now have a (venv) prefix in front of it.

Next, install Toga into your virtual environment:

Before you install toga, you’ll need to install some system packages. These instructions are different on almost every version of Linux; here are some of the common alternatives:

If you’re not using one of these, you’ll need to work out how to install the developer libraries for python3, cairo, pango, and gobject-introspection (and please let us know so we can improve this documentation!)

If you get other errors, please check that you followed the prerequisite instructions.

After a successful installation of Toga you are ready to get coding.

Write the appВ¶

Create a new file called helloworld.py and add the following code for the “Hello world” app:

Let’s walk through this one line at a time.

The code starts with imports. First, we import toga:

Then we set up a handler, which is a wrapper around behavior that we want to activate when the button is pressed. A handler is just a function. The function takes the widget that was activated as the first argument; depending on the type of event that is being handled, other arguments may also be provided. In the case of a simple button press, however, there are no extra arguments:

We want to put a button in the window. However, unless we want the button to fill the entire app window, we can’t just put the button into the app window. Instead, we need create a box, and put the button in the box.

A box is an object that can be used to hold multiple widgets, and to define padding around widgets. So, we define a box:

We can then define a button. When we create the button, we can set the button text, and we also set the behavior that we want to invoke when the button is pressed, referencing the handler that we defined earlier:

Now we will make the button take up all the available width:

The flex attribute specifies how an element is sized with respect to other elements along its direction. The default direction is row (horizontal) and since the button is the only element here, it will take up the whole width. Check out style docs for more information on how to use the flex attribute.

The next step is to add the button to the box:

The button has a default height, defined by the way that the underlying platform draws buttons. As a result, this means we’ll see a single button in the app window that stretches to the width of the screen, but has a 50 pixel space surrounding it.

Now we’ve set up the box, we return the outer box that holds all the UI content. This box will be the content of the app’s main window:

The entry point for the project then needs to instantiate this entry point and start the main app loop. The call to main_loop() is a blocking call; it won’t return until you quit the main app:

Running the appВ¶

Here is the command to run for your platform from your working directory:

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *