IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> 详解beeware(三):自制浏览器与打包 -> 正文阅读

[Python知识库]详解beeware(三):自制浏览器与打包

创建项目

(使用的是IE内核)
使用briefcase创建一个项目(可见我的系列教程):

briefcase new

项目名是browserpy,如下:

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]: browserpy

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 'browserpy',
but you can use another name if you want.

App Name [browserpy]:

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.browserpy).

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 [browserpy]:

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

Description [My first application]: a python browser

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/browserpy]:

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]:

Generating a new application 'browserpy'

完成后:

cd browserpy

此时的项目结构:

browserpy
│  .gitignore
│  LICENSE
│  pyproject.toml
│  README.rst
│
└─src
    └─browserpy
        │  app.py
        │  __init__.py
        │  __main__.py
        │
        └─resources
                browserpy.icns
                browserpy.ico
                browserpy.png
                __init__.py

编写代码

进入src/browserpy/app.py
toga文档找来的demo改一改:

"""
a python browser
"""
import toga
from toga.style.pack import CENTER, COLUMN, ROW, Pack


class browserpy(toga.App):
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name)

        self.webview = toga.WebView(style=Pack(flex=1))
        self.url_input = toga.TextInput(
            initial='https://www.baidu.com/',
            style=Pack(flex=1)
        )

        box = toga.Box(
            children=[
                toga.Box(
                    children=[
                        self.url_input,
                        toga.Button('浏览', on_press=self.load_page, style=Pack(width=50, padding_left=5)),
                    ],
                    style=Pack(
                        direction=ROW,
                        alignment=CENTER,
                        padding=5,
                    )
                ),
                self.webview,
            ],
            style=Pack(
                direction=COLUMN
            )
        )

        self.main_window.content = box
        self.webview.url = self.url_input.value

        # Show the main window
        self.main_window.show()

    def load_page(self, widget):
        self.webview.url = self.url_input.value


def main():
    return browserpy('Graze', 'org.beeware.graze')

测试代码

briefcase dev

打包

windows

输入:

briefcase create windows
briefcase build windows
briefcase run windows
briefcase package windows

MacOS

输入:

briefcase create macOS
briefcase build macOS
briefcase run macOS
briefcase package macOS

linux

输入:

briefcase create linux
briefcase build linux
briefcase run linux
briefcase package linux

android

输入:

briefcase create android
briefcase build android
briefcase run android
briefcase package android

IOS

输入:

briefcase create iOS
briefcase build iOS
briefcase run iOS
briefcase package iOS

tvOS

暂无打包方法。

  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2021-09-09 11:42:11  更:2021-09-09 11:44:43 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 13:22:55-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码