赞
踩
目前市面上大部分的桌面应用都是C#、C++、Java进行开发,这边的话,不推荐大家使用wxPython进行开发桌面应用,当然纯属兴趣可以尝试。
wxPython 官网:https://wxpython.org/
wxPython 是什么?官方介绍给出了介绍
wxPython is a cross-platform GUI toolkit for the Python programming language. It allows Python programmers to create programs with a robust, highly functional graphical user interface, simply and easily.
wxPython是一个用于Python编程语言的跨平台GUI工具包。它允许Python程序员创建具有健壮、功能强大的图形用户界面的程序,简单而容易。
It is implemented as a set of Python extension modules that wrap the GUI components of the popular wxWidgets cross platform library, which is written in C++.
它被实现为一组Python扩展模块,用来包装流行的wxWidgets跨平台库的GUI组件,它是使用C++语言编写的。
安装 wxpython 第三方的库,国外的网站下载,速度肯定会很慢,建议使用镜像站进行下载。
常见 pip 镜像源 Mirror source(国内源)
清华镜像源:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云镜像源:http://mirrors.aliyun.com/pypi/simple/
中国科技大学镜像源: https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学镜像源:http://pypi.hustunique.com/
山东理工大学镜像源:http://pypi.sdutlinux.org/
豆瓣镜像源:http://pypi.douban.com/simple/
临时使用 pip 镜像源可以在使用 pip 的时候加参数:-i https://pypi.tuna.tsinghua.edu.cn/simple
举例使用清华镜像源进行下载 wxPython
pip3 install wxPython -i https://pypi.tuna.tsinghua.edu.cn/simple
Every programming language and UI toolkit needs to have a Hello World example. I think it’s the law in most jurisdictions. Their intent is obviously to tell you everything you need to know in order to select the language or toolkit for your own use.
每种编程语言和UI工具包都需要有一个HelloWorld的示例。我认为这是大多数管辖的规范。他们的目的是清楚地去告诉你需要知道的一切,以便选择你自己使用的语言或工具包。
安装好界面库以后,我们先实现入门程序的制作:
# 先创建一个程序
app = wx.App()
# 创建完程序,下一步就是创建一个窗口(Frame)
frame = wx.Frame(None, title='helloworld', size=(300, 200))
# 创建完成窗口,我们想要显示结果怎么办?(Show)
frame.Show()
# 最后运行主程序MainLoop(),事件循环
app.MainLoop()
这边就是介绍下 Frame 类初始化的相关参数,这是类__init__
的源码:
Param:title 生成GUI窗口的名称
Param:size 生成GUI窗口的尺寸,参数类型是 Turple 元组类型(窗口宽度,窗口高度)
def __init__(self, parent=None, id=None, title=None, pos=None, size=None, style=None, name=None):
pass
# real signature unknown; restored from __doc__ with multiple overloads
运行结果展示如下所示:
Five lines of code to create and show a window, and run an event handler. That’s really all it takes.
What, you think 5 lines is too many? Okay, fine. Here it is in one line
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。