1. wxpython-Layout Management
Dimension device
-Sizer, WX. Boxsizer
->>> Help (WX. Boxsizer)
-Role: Manage the component layout locations added to it
Usage
Hbox = wx. Boxsizer ([WX. Horizontal])
VBox = wx. Boxsizer (WX. VERTICAL)
-add panel to facilitate layout
-Add components for management
Sizer.add (component, proportion=,flag=,border=)
Example
#-*-encoding:utf-8-*-
import wx
app = wx. APP ()
win = wx. Frame (None, title= "My Notebook", size= (410, 335))
panel = wx. Panel (Win)
Openbutton = wx. button (panel, label= "Open")
Savebutton = wx. button (panel, label= "Save")
filepathtxt = wx. Textctrl (panel)
contenttxt = wx. Textctrl (panel, style=wx.te_multiline)
#默认水平, place file path text box Open button Save button
# Proportion: 1 of the total
# Flag:expand expansion Exhibition
Hbox = WX. Boxsizer ()
Hbox. ADD (Filepathtxt, Proportion=1, flag=wx. EXPAND)
Hbox. ADD (Openbutton, proportion=0, flag=wx. Left, border=5)
Hbox. ADD (Savebutton, proportion=0, flag=wx. Left, border=5)
#垂直,
bbox = wx. Boxsizer (WX. VERTICAL)
bbox. ADD (Hbox, proportion=0, flag=wx. Expand|wx. All, border=5)
bbox. ADD (Contenttxt, proportion=1,flag=wx. Expand|wx. Left|wx. Bottom|wx. right,border=5)
panel. Setsizer (bbox)
win. Show ()
app. Mainloop ()
2. wxpython-Event Handling
Bind the event handler function through the component's bind (func)
For example, click on the button to print "Hello" to the console
def printhelloevthandle (evt):
print "Hello"
Btn. Bind (WX. Evt_button, Printhelloevthandle)
Example:
#-*-encoding:utf-8-*-Import wx def openfileeventhandle (evt): filepath = Filepathtxt.getvalue () fopen = open (f
Ilepath) content = Fopen.read () fopen.close () Contenttxt.setvalue (content) def savefileeventhandle (evt): filepath = Filepathtxt.getvalue () fopen = open (filepath, "w") content = Contenttxt.getvalue () Fopen.write (con Tent) Fopen.close () app = WX. APP () win = WX. Frame (None, title= "My Notebook", size= (410, 335)) panel = WX. Panel (Win) Openbutton = wx. button (panel, label= "Open") Savebutton = wx. button (panel, label= "Save") Filepathtxt = wx. Textctrl (panel) contenttxt = wx. Textctrl (panel, style=wx.te_multiline) #绑定事件 openbutton.bind (WX. Evt_button, Openfileeventhandle) savebutton.bind (WX. Evt_button, Savefileeventhandle) #默认水平, place the file Path text box Open button to save the button # proportion: A fraction of the total 1 # flag:expand Extension Hbox = wx. Boxsizer () Hbox. ADD (Filepathtxt, Proportion=1, flag=wx. EXPAND) Hbox. ADD (Openbutton, proportion=0, flag=wx. Left, border=5) Hbox. ADD (savebutTon, proportion=0, flag=wx. Left, border=5) #垂直, bbox = wx. Boxsizer (WX. VERTICAL) bbox. ADD (Hbox, proportion=0, flag=wx. Expand|wx. All, border=5) bbox. ADD (Contenttxt, proportion=1,flag=wx. Expand|wx. Left|wx. Bottom|wx. right,border=5) panel. Setsizer (Bbox) win. Show () app.
Mainloop ()