27-python_gui-Layout Management-Event handling __python

Source: Internet
Author: User
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 ()



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.