Python Learning Note 14: WxPython Demo

Source: Internet
Author: User

First, Introduction

Wxpython is a good set of GUI graphics libraries in the Python language, allowing Python programmers to easily create complete GUI user interfaces with full function keys. Wxpython is provided to the user as an excellent cross-platform GUI library wxwidgets python package and Python module.

Second, installation

Reference official website: http://www.wxpython.org/download.php

Third, DEMO

This demo is a simple Notepad software that can open files, modify and save.

ImportWxapp=WX. APP () win=WX. Frame (None, title="Simple Editor", size= (410, 335)) bkg=WX. Panel (Win)defOpenFile (evt): Dlg=WX. FileDialog (Win,"Open",        "",        "",        "All files (*. *) |*.*", WX. Fd_open|WX. fd_file_must_exist) FilePath="'    ifDlg. ShowModal () = =Wx.ID_OK:filepath=dlg. GetPath ()Else:        returnfilename. SetValue (filepath) fopen=Open (filepath) fcontent=fopen.read () contents. SetValue (fcontent) fopen.close ()defSaveFile (evt): Fcontent=contents. GetValue () fopen= open (filename. GetValue (),'W') Fopen.write (fcontent) fopen.close () openbtn= WX. Button (bkg, label='Open') Openbtn.bind (WX. Evt_button, OpenFile) savebtn= WX. Button (bkg, label='Save') Savebtn.bind (WX. Evt_button, saveFile) filename= WX. Textctrl (bkg, style=wx.te_readonly) Contents= WX. Textctrl (bkg, style=wx.te_multiline) Hbox=WX. Boxsizer () Hbox. ADD (OPENBTN, proportion=0, Flag=wx. Left | Wx. All, border=5) Hbox. ADD (filename, proportion=1, Flag=wx. EXPAND | Wx. TOP | Wx. BOTTOM, border=5) Hbox. ADD (SAVEBTN, proportion=0, Flag=wx. Left | Wx. All, border=5) Bbox=WX. Boxsizer (WX. VERTICAL) bbox. ADD (Hbox, proportion=0, Flag=wx. EXPAND |WX. All) bbox. ADD (contents, proportion=1, Flag=wx. EXPAND | Wx. Left | Wx. BOTTOM |WX. Right, border.=5) bkg. Setsizer (Bbox) win. Show () app. Mainloop ()

Operating effect:

Python Learning Note 14: WxPython Demo

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.