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