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)