Graphical user interface
This paper uses Wxpython
The methods in the WX package start with uppercase captions
Import Wxdef Load (event): File = open (filename. GetValue ()) contents. SetValue (File.read ()) File.close () def Save (event): File = open (filename. GetValue (), ' W ') file.write (contents. GetValue ()) file.close () app = WX. APP () win = WX. Frame (None, title = "Simple Editor", size = (410, 335)) bkg = WX. Panel (Win) loadbtn = wx. Button (bkg, label = "Open") Loadbtn.bind (WX. Evt_button, load) # button binding function savebtn = WX. Button (bkg, label = "Save") Savebtn.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 (loadbtn, proportion = 0, flag = wx. Left, border = 5) Hbox. ADD (savebtn, 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) bkg. Setsizer (VBox) win. Show () app. Mainloop ()
Wx. The Boxsizer parameter defaults to horizontal, WX. Vertical is vertical.
The flag parameter is similar to style. Wx. The expand markup component expands to the allocated space. Wx. Left, WX. Right, WX. TOP, WX. BOTTOM, WX. All corresponds to which side.
The proportion parameter is the amount of space allocated as the window changes size.
Python write GUI