A, python gui (graphical) Module Description:
Tkinter: python is the most simple graphical module, a total of only 14 kinds of formation
Pyqt: python is the most complex and most widely used graphical
Wx: python which is centered in a graphical, learning structure is very clear
Pywin: a module, camera control (OpenCV) under python windows, commonly used in the production of plug
Two, wx module installation:
C:\Users\Administrator> pip install wxpython
Third, the graphical presentation
Four, wx Introducing the major
1, frame (window)
parameter:
parent = None # parent element, if to None, the representative of top-level window
None # id = identification component only, if the representative system assigns id id -1
title = None # widget name
Position pos = None # component, the component is from the upper left corner from the parent component or the desktop and on the left
size = size None # components, width and height
style = style None # assembly
None # name = name components, is used to identify the components, but for traditional values
2, TextCtrl (text box)
parameter:
parent = None # parent element, if to None, the representative of top-level window
None # id = identification component only, if the representative system assigns id id -1
Among the contents of value = None # textbox
GetValue # get the value of the text box
SetValue # value of the text box
Position pos = None # component, the component is from the upper left corner from the parent component or the desktop and on the left
size = size None # components, width and height
style = style None # assembly
authentication validator = None #
None # name = name components, is used to identify the components, but for traditional values
3, Button (Button)
parameter:
parent = None # parent element, if to None, the representative of top-level window
None # id = identification component only, if the representative system assigns id id -1
lable = None # button label
Position pos = None # component, the component is from the upper left corner from the parent component or the desktop and on the left
size = size None # components, width and height
style = style None # assembly
authentication validator = None #
None # name = name components, is used to identify the components, but for traditional values
Other components similar parameters
4, the underlying code to create a window
Basic to create a window Code Description: <br> <br> import wx # wx module introduced <br>
app = wx.App () # example of a main loop <br>
frame = wx.Frame (None) # instantiating a window <br>
frame.Show () # call window display function <br>
app.MainLoop () # start the main loop
Results as shown:
Five, Gui write simple example
A GUI interface to achieve the following in the input text file address above the text box, click on the "Open" button will display the contents of a text file in the text box below.
1, graphical write
content_text = wx.TextCtrl (frame, pos = (5,39), size = (475,300), style = wx.TE_MULTILINE) # wx.TE_MULTILINE wrap functionality can be achieved, if not add this feature to display text documents appear on one line
frame.Show () app.MainLoop ()
2, event binding
Defined event function
Event function has only one parameter, called the event
Component binding conditions and departure events
open_button.Bind(wx.EVT_BUTTON,openfile)
3, complete code
Sixth, the size is
According to the above GUI code has a flaw, since we have fixed the various components of the size, so when the stretching frame, corresponding to the corresponding component does not stretch, comparing user experience.
To solve the problem, we can use the size of the device layout, similar to HTML CSS styles.
1, BoxSizer (sizer)
Acting on the size of the canvas (Panel)
The default horizontal layout
Vertical layout can be adjusted
In accordance with the relative proportions of
2, step
Examples of size (which may be a plurality)
Adding components to different sized vessel
Setting the relative proportions of the filled and direction style, border parameters
Major dimension is provided
3, the code above is rewritten by size
By size layout, regardless of the wide-body stretching, the internal components will vary proportionally.