Python write GUI

Source: Internet
Author: User

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

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.