Wxpython Notes (i)

Source: Internet
Author: User

Frame is a framework that can be directly understood as a window. To create a subclass of a frame, you need to call the constructor of the frame class, with the following prototype:

Wx. Frame (parent, Id=-1, title= "", pos=wx. Defaultposition, Size=wx. DefaultSize, Style=wx. Default_frame_style, name= "FRAME")

The meaning of each parameter:

Parent: The top-level window uses none directly.

ID: identification, there are three ways to assign: 1, you specify a positive number, but to ensure that the same form can not be repeated, 2, the value of 1 or Wx.id_any, is automatically assigned by the system, you can pass frame. GetId () to obtain this value; 3, use WX. NewId () function to create the.

POS: Window position.

Size: Window sizes.

Style: Styles, wherein, WX. The value of Default_frame_style is: Wx.maximize_box | Wx. Minimize_box | Wx.   Resize_border | Wx. System_menu | Wx. CAPTION | Wx. Close_box

Add a style using "|", remove a style using "^"

Use of Wxpython

1) Create an Application object
App = WX. APP ()

2) Access to application management
App. Mainloop ()

3) Create window Window–frame
Win = WX. Frame (None)
Or
Win = WX. Frame (None, title= "Simple Editor")


4) display window:
Win. Show ()

Eg: a program with only one window
#!/usr/bin/python
#encoding =utf-8

Import WX
App=wx. APP () #创建应用程序对象
Win=wx. Frame (None)
Win. Show ()

App. Mainloop () #进入程序管理



5) Add components to the window
The format is:
BTN = wx. Button (Win)

A. Set the title, label information for the component.
The format is:
Loadbutton = wx. Button (Win, label= ' Open ')

B. Set the location (POS) for the component, size (size)

6) Add Component---text box
A. Default text box: Text control:wx. Textctrl
B. Set to Text area: Style=wx.te_multiline |wx. HScroll
#!/usr/bin/python
#encoding =utf-8

Import WX
App=wx. APP () #创建应用程序对象
Win=wx. Frame (none,title= "My Program", Size= (410,335))

Fbutton=wx. Button (win,label= "Open", pos= (225,5), size= (80,25))
Sbutton=wx. Button (win,label= "Save", pos= (315,5), size= (80,25))
Filename=wx. Textctrl (win,pos= (5,5), size= (210,25))
Content=wx. Textctrl (win,pos= (5,35), size= (390,260), style=wx.te_multiline| WX. HScroll) #wx. Te_multiline to get multiple lines of text (with vertical scroll bars by default) and Wx.hscroll to get horizontal scroll bars
Win. Show ()

App. Mainloop () #进入程序管理

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.