Python实例之wxpython中Frame使用方法
本节为大家分享的例子是wxpython Frame的用法。
例子:
代码如下:
#!/usr/bin/python
# -*- coding: GBK -*-
# simple.py
import wx
app = wx.App()
frame = wx.Frame(None)
frame.Show()
app.MainLoop()
例2,
代码如下:
#!/usr/bin/python
告诉程序 python 解释器的路径,只是在 linux 系统下有用,在 Windows 下写上这行代码不起作用,但是也没问题
# -*- coding: GBK -*-
告诉 python 系统字符编码,这样我们就可以在程序中使用中文汉字了,如果没有这一行就是乱码。Windows 下是 GBK,Linux 下是UTF-8
app = wx.App()
初始化应用程序
frame = wx.Frame(None)
frame.Show()
创建一个 Frame (就是窗体),并显示出来。
app.MainLoop()
应用程序进入消息循环
Frame 其实就是窗体,前面生成窗体时没有给他任何参数,只生成了一个默认的窗体,生成默认窗体的代码:
frame = wx.Frame(None)
其实 wx.Frame 可以传入很多参数,由此来控制生成窗体的样式和行为,现在来看看 Frame构造函数的原型:
__init__(self, Window parent, int id=-1, String title=EmptyString,
Point pos=DefaultPosition, Size size=DefaultSize,
long style=DEFAULT_FRAME_STYLE, String name=FrameNameStr)
参数1:parent
当前窗口的父窗口,如果当前窗口是top-level window的话,则parent=None,如果不是顶层窗口,则它的值为所属frame的名字
参数2:id
窗体编号。如果设置为-1,则系统自动给他分配一个编号。默认为-1.
参数3:title
窗体的标题栏,即Caption。默认为空。
参数4:pos
窗体的位置坐标。默认值为(-1,-1),则窗体的位置由系统决定。
参数5:size
窗体的大小。默认值为(-1,-1),则窗体的大小由系统决定。
参数6:style
窗体样式。默认值为 DEFAULT_FRAME_STYLE
默认样式 DEFAULT_FRAME_STYLE 是下面这些值的复合:
wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER |
wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN
它包括最小化按钮、最大化按钮、系统菜单、标题栏、关闭按钮、可变大小等等。您也可以根据自己的需求改变样式,具体请参照帮助。
参数7:name
窗体名称。
可以看到,7个参数中6个都有默认值,只有第一个参数 parent 需要设置一下,所以一个最简单的窗体就是:
Python代码 收藏代码
frame = wx.Frame(None)
窗体标题:
Python代码 收藏代码
frame = wx.Frame(None,title="Hello World")
位置和大小:
Python代码 收藏代码
frame = wx.Frame(None,title="世界你好",size=(300,150),pos=(200,200))
样式一:只有一个光秃秃的标题栏
Python代码 收藏代码
frame = wx.Frame(None,style=wx.CAPTION)
样式二:只有客户区,没有标题栏,也不能改变大小
Python代码 收藏代码
frame = wx.Frame(None,style=0)
样式三:只有一个关闭按钮,不能改变大小
代码如下:
frame = wx.Frame(None,style= wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)
wx.DEFAULT_FRAME_STYLE :这是每个窗口的缺省风格,包含标题、可调节大小的边框,最大最小化按钮、关闭按钮和系统菜单。
wx.CAPTION :在框架上增加一个标题栏,它显示该框架的标题属性。
wx.CLOSE_BOX :指示系统在框架的标题栏上显示一个关闭框,使用系统默认的位置和样式。
Wx.FRAME_ON_TOP : 置顶窗口
w x.FRAME_SHAP ED :用这个样式创建的框架可以使用SetShape()方法去创建一个非矩形的窗口。
wx.FRAME_TOOL_WINDOW :通过给框架一个比正常更小的标题栏,使框架看起来像一个工具框窗口。在Windows下,使用这个样式创建的框架不会出现在显示所有打开窗口的任务栏上。
wx.MAXIMIZE_BOX :指示系统在框架的标题栏上显示一个最大化框,使用系统默认的位置和样式。
wx.MINIMIZE_BOX :指示系统在框架的标题栏上显示一个最小化框,使用系统默认的位置和样式。
wx.RESIZE_BORDER :给框架增加一个可以改变尺寸的边框。
wx.SIMPLE_BORDER :没有装饰的边框。不能工作在所有平台上。
wx.SYSTEM_MENU :增加系统菜单(带有关闭、移动、改变尺寸等功能)和关闭框到这个窗口。在系统菜单中的改变尺寸和关闭功能的有效性依赖于wx.MAXIMIZE_BOX, wx.MINIMIZE_BOX和wx.CLOSE_BOX样式是否被应用。
wx.FRAME_EX_META :如果时在 MacOS 中,这个属性用于是否显示“金属风格”
wx.FRAME_EX_CONTEXTHELP :是否有联机帮助按钮。
wx.FRAME_FLOAT_ON_PARENT :窗口是否显示在最上层,与 wxSTAY_ON_TOP 不同,它必须有一个父窗口。
frame窗体风格通过style属性来设置,例如:
style=wx.SYSTEM_MENU|wx.MINIMIZE_BOX|wx.CLOSE_BOX|wx.CAPTION

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



A brief introduction to python GUI programming GUI (Graphical User Interface, graphical user interface) is a way that allows users to interact with computers graphically. GUI programming refers to the use of programming languages to create graphical user interfaces. Python is a popular programming language that provides a rich GUI library, making Python GUI programming very simple. Introduction to Python GUI library There are many GUI libraries in Python, the most commonly used of which are: Tkinter: Tkinter is the GUI library that comes with the Python standard library. It is simple and easy to use, but has limited functions. PyQt: PyQt is a cross-platform GUI library with powerful functions.

Python is a concise, easy to learn, and efficient programming language. It is widely used in various fields such as data science, artificial intelligence, game development, network programming, etc. Although Python comes with some GUI libraries, their functions are relatively simple and cannot meet the needs of various complex applications. Therefore, there are many GUI libraries to choose from in Python, among which wxPython is one of them, which this article will introduce in detail. Introduction to wxPython wxPython is an open source, cross-platform GUI library based on

Introduction to pythonGUI programming PythonGUI programming, that is, graphical user interface programming, is the process of creating application program interfaces using the Python language. GUI applications usually have elements such as windows, buttons, text boxes, menus, etc., through which users can interact with the program. Python GUI programming has many benefits. First, it can make your program more beautiful and easier to use. Secondly, it can make your program cross-platform, that is, it can run on different operating systems. Third, it can make your program more flexible and easier to extend. Commonly used Python GUI libraries In Python, there are many commonly used GUI libraries, including Tkinter, PyQt, wxPython and PyG

PythonGUI programming, as the name suggests, is a programming technology that uses the Python language to create a graphical user interface (GUI). Python GUI programming has many advantages, such as: cross-platform, rich third-party library support, concise syntax, etc. Therefore, Python GUI programming is deeply loved by programmers and is widely used in various types of application development. In Python GUI programming, the most commonly used third-party libraries are Tkinter, PyQt and wxPython. Tkinter is part of the Python standard library and is simple and easy to use, but has limited functionality. PyQt and wxPython are both powerful third-party GUI libraries, but they are also more

1. Basics of pythonGUI programming PythonGUI programming refers to the process of creating a graphical user interface (GUI) using the Python language. GUI is the interface for users to interact with applications, usually consisting of windows, buttons, text boxes, list boxes and other controls. Python provides a variety of GUI libraries, such as Tkinter, PyQt, wxPython, etc. These libraries provide rich controls and event handling mechanisms, allowing Python programmers to easily create beautiful and practical GUI applications. 2. Getting Started with PythonGUI Programming Installing the PythonGUI Library Before starting GUI programming, you need to install the PythonGUI library first. Taking Tkinter as an example, you can

Python is an easy-to-learn, powerful programming language suitable for development in various fields. In Python, there are a variety of graphical user interface (GUI) libraries available that help developers create interactive desktop applications. This article will introduce some commonly used Python GUI libraries and provide specific code examples. Tkinter: Tkinter is Python's standard GUI library that provides functionality for creating simple window applications. Using Tkinter, we can easily

The difference between iframe and frame is: 1. iframe is a tag in HTML5, and frame is a tag in HTML4; 2. iframe is an independent HTML document, and frame is a divided area of an HTML document; 3. iframe can be set by setting attributes To control whether users are allowed to interact, while frame does not have these functions; 4. iframe can control whether to allow cross-domain loading of web pages by setting attributes, while frame does not have this function.

Introduction to pythonGUI Programming PythonGUI programming is the process of creating a graphical user interface. Graphical user interface (GUI) is the interface for interaction between the user and the computer. It is an essential component of all modern computer systems. Python GUI programming provides an easy way to create applications with intuitive user interfaces. Getting started with PythonGUI programming Getting started with PythonGUI programming is very simple. You only need to install a GUI library such as Tkinter, PyQt or wxPython. These libraries provide easy ways to create GUIs. Tkinter is Python's own GUI library. It's very simple and easy to use, but has limited functionality. PyQt is a more powerful
