GUI programming of Python (10)

Source: Internet
Author: User

Implemented on Windwos: using the Wxpython module

#!/usr/bin/env python# encoding:utf-8import wx# Create an Open button to trigger the event corresponding to the function Def load (event): File = open (filename. GetValue ()) contents. SetValue (File.read ()) File.close () #创建save按钮触发的事件对应的函数def Save (Event): File = open (filename. GetValue (), ' W ') file.write (contents. GetValue ()) file.close () #创建应用程序对象app = WX. APP () #创建窗口 (frame instance) win = WX. Frame (none,title= "Simple Editor", size= (410,335)) #背景组件bkg = WX. Panel (Win) #在窗口添加按钮, and bind event Loadbutton = WX. Button (bkg,label= ' open ') loadbutton.bind (WX. Evt_button,load) Savebutton = wx. Button (bkg,label= ' Save ') savebutton.bind (WX. Evt_button,save) #文本控制对象filename = wx. Textctrl (bkg) contents = wx. Textctrl (Bkg,style=wx.te_multiline | wx. HScroll) #水平调整hbox = wx. Boxsizer () Hbox. ADD (filename,proportion=1,flag=wx. EXPAND) Hbox. ADD (loadbutton,proportion=0,flag=wx. left,border=5) Hbox. ADD (savebutton,proportion=0,flag=wx. left,border=5) #垂直方向调整vbox = wx. Boxsizer (WX. VERTICAL) VBox. ADD (Hbox, proportion=0,flag=wx. EXPAND | Wx. all,border=5) VBox. ADD (contents,proportion=1,flag=wx. EXPAND | WX.left | Wx. BOTTOM | Wx. right,border=5) #调用面板的SetSizer设定尺寸bkg. Setsizer (VBox) #调用app. Mianloop need to call the window before the law, otherwise he will always hide win. Show () app. Mainloop ()

GUI programming of Python (10)

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.