详解beeware(四): toga应用一(box组件)

本文将指导你如何使用Beeware的Toga框架,从头开始构建一个简单的Python应用。步骤包括设置项目名称、选择合适的包名和bundle identifier,直至创建基本UI组件。跟随教程,一步步创建HelloWorld应用。
摘要由CSDN通过智能技术生成

最近有事情,很久没更新了。再写一篇beeware的文章。
先创建个项目:

python -m briefcase new

如下设置:

Let's build a new Briefcase app!


First, we need a formal name for your application. This is the name that will
be displayed to humans whenever the name of the application is displayed. It
can have spaces and punctuation if you like, and any capitalization will be
used as you type it.

Formal Name [Hello World]: toga_demo

Next, we need a name that can serve as a machine-readable Python package name
for your application. This name must be PEP508-compliant - that means the name
may only contain letters, numbers, hyphens and underscores; it can't contain
spaces or punctuation, and it can't start with a hyphen or underscore.

Based on your formal name, we suggest an app name of 'toga_demo',
but you can use another name if you want.

App Name [toga_demo]:

Now we need a bundle identifier for your application. App stores need to
protect against having multiple applications with the same name; the bundle
identifier is the namespace they use to identify applications that come from
you. The bundle identifier is usually the domain name of your company or
project, in reverse order.

For example, if you are writing an application for Example Corp, whose website
is example.com, your bundle would be ``com.example``. The bundle will be
combined with your application's machine readable name to form a complete
application identifier (e.g., com.example.toga_demo).

Bundle Identifier [com.example]:

Briefcase can manage projects that contain multiple applications, so we need a
Project name. If you're only planning to have one application in this
project, you can use the formal name as the project name.

Project Name [toga_demo]:

Now, we need a one line description for your application.

Description [My first application]:

Who do you want to be credited as the author of this application? This could be
your own name, or the name of your company you work for.

Author [Jane Developer]: stripe-python

What email address should people use to contact the developers of this
application? This might be your own email address, or a generic contact address
you set up specifically for this application.

Author's Email [stripe-python@example.com]:

What is the website URL for this application? If you don't have a website set
up yet, you can put in a dummy URL.

Application URL [https://example.com/toga_demo]:

What license do you want to use for this project's code?

Select one of the following:

    [1] BSD license
    [2] MIT license
    [3] Apache Software License
    [4] GNU General Public License v2 (GPLv2)
    [5] GNU General Public License v2 or later (GPLv2+)
    [6] GNU General Public License v3 (GPLv3)
    [7] GNU General Public License v3 or later (GPLv3+)
    [8] Proprietary
    [9] Other

Project License [1]: 2

What GUI toolkit do you want to use for this project?

Select one of the following:

    [1] Toga
    [2] PySide2 (does not support iOS/Android deployment)
    [3] PursuedPyBear (does not support iOS/Android deployment)
    [4] None

GUI Framework [1]:

接下来:

cd toga_demo
open src/toga_demo/app.py

使用toga.Box创建一个盒子组件,类似tkinterFrameHTML5div

"""
My first application
"""
import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW


class toga_demo(toga.App):

    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """
        main_box = toga.Box()

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
        
        inside_box = toga.Box('inside_box')
        main_box.add(inside_box)
        inside_box.style.update(direction=COLUMN, padding_top=10, background_color='#2F2F2F')


def main():
    return toga_demo()

使用如下运行:

python -m briefcase dev

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值