Wxpython Control Learning: WX. ComboBox

Source: Internet
Author: User

Wx. ComboBox consists of an editing box and a list. It can be displayed as a static list with editable or read-only text boxes, text areas with drop-down lists, or drop-down lists without text boxes. Only one wx. ComboBox can be selected. The wx. ComboBox option starts from 0. If you need to customize wx. ComboBox, you can refer to wx. comboctrl, wx. ownerdrawncombobox, wx. combopopup, and the upcoming wx. bitmapcombox controls.

1. Style

Wx. cb_simple creates a ComboBox with a list display. Only Windows is supported.

Wx. cb_dropdown create a ComboBox with a drop-down list

Wx. cb_readonly is the same as wx. cb_dropdown. However, only the string selected as the ComboBox option can be selected. Strings not in the selection list cannot be entered into the text box in the control.

Wx. cb_sort list items are sorted alphabetically

Wx. te_proces_enter the control in this style will generate the event wx. evt_command_text_enter (otherwise, pressing the Enter key is either internally processed by the control or used for control navigation ). Only Windows is supported.

2. Events

Evt_combobox (ID, func) // process the Wx. evt_command_combobox_selected event when an item in the list is selected. Note that the selected value is returned when getvalue is called.

Evt_text (ID, func) // when the ComboBox text changes, process the Wx. evt_command_text_updated event

Evt_text_enter (ID, func) // when you press the Enter key in ComboBox, process the Wx. evt_text_enter event.

 

 

 #  -*-Coding: UTF-8 -*-  #  -------------------------------------------------------------------------------  #  Name: Module 1  #  Purpose:  ##  Author: ankier  ##  Created: 10/10/2012  #  Copyright: (c) ankier 2012 #  Licence: <your licence>  #  -------------------------------------------------------------------------------  Import  WX  Class  Comboboxframe (wx. Frame ):  Def   _ Init __  (Self): WX. Frame.  _ Init __ (Self, none,-1, '  Combo box example ' , Size = (350,300 ) Panel = Wx. Panel (self,-1 ) Samplelist = [ '  Zero  ' , '  One  ' , '  Two  ' , '  Three  ' ,'  Four  ' , '  Five  ' , '  Six  ' , '  Seven  ' , '  Eight  '  ] Flexsizer = Wx. flexgridsizer (,) Flexsizer. addgrowablecol ( 1 ) Flexsizer. addgrowablecol ( 3 )  #  Define the ComboBox of a common style, accept keyboard input, but do not change the item Commonlable = wx. statictext (panel,-1, "  Normal style  "  ) Commoncombobox = Wx. ComboBox (panel,-1, value = "  Zero  " , Choices = samplelist, style =Wx. cb_dropdown)  #  Define a simple ComboBox, Simplelable = wx. statictext (panel,-1, "  Simple Style:  "  ) Simplecombobox = Wx. ComboBox (panel,-1, value = "  Zero  " , Choices = samplelist, style = Wx. cb_simple)  #  Define the read-only ComboBox, Readonlylable = wx. statictext (panel,-1,"  Read-Only style:  "  ) Readonlycombobox = Wx. ComboBox (panel,-1, value = "  Zero  " , Choices = samplelist, style = Wx. cb_readonly)  #  Define secondary linkage drop-down list Citydict = { '  Anhui Province  ' :[ "  Hefei " , "  Huainan  " ], "  Jiangsu  " :[ "  Suzhou  " , "  Nanjing  "  ]}  #  Define Level 1 menus Provicelable = wx. statictext (panel,-1,"  Province:  "  ) Provicecombobox = Wx. ComboBox (panel,-1, value = citydict. Keys () [0], choices = citydict. Keys (), style = Wx. cb_readonly)  #  Define Level 2 menu Citylable = wx. statictext (panel,-1, "  City:  "  ) Citycombobox = Wx. comboBox (panel,-1, value = citydict [citydict. keys () [0] [0], choices = citydict [citydict. keys () [0], style =Wx. cb_readonly) flexsizer. addzer ([(commonlable, 0, wx. Shaped | Wx. align_right), (commoncombobox, 1, wx. Expand), (simplelable, 0, wx. Shaped | wx. align_right), (simplecombobox, 1 , Wx. Expand), (readonlylable, 0, wx. Shaped | Wx. align_right), (readonlycombobox, 1, wx. expand), (wx. size (6, 6), 0, wx. shaped | wx. align_right), (wx. size (6, 6), 1 , Wx. Expand), (provicelable, 0, wx. Shaped | Wx. align_right), (provicecombobox, 1, wx. expand), (wx. size (6, 6), 0, wx. shaped | wx. align_right), (wx. size (6, 6), 1 , Wx. Expand), (citylable, 0, wx. Shaped | Wx. align_right), (citycombobox, 1, wx. expand), (wx. size (6, 6), 0, wx. shaped | wx. align_right), (wx. size (6, 6), 1, Wx. Expand)]) panel. setsizerandfit (flexsizer)  #  When a level-1 drop-down list switch is defined, the response events of level-2 menu items are refreshed. Self. _ Provincecombobox = Provicecombobox self.  _ Secitydict = Citydict self.  _ Citycombobox = Citycombobox panel. BIND (wx. evt_combobox, self.  _ Oncomboboxselected  , Provicecombobox ,)  Def  _ Oncomboboxselected  (Self, event): currentprovinceindex = Self. _ Provincecombobox  . Getselection ()  If Wx. not_found = currentprovinceindex: Return  Value = Self. _ Provincecombobox  . Getitems () [currentprovinceindex]  #  Note that the UTF-8 format is inconsistent when storing Chinese characters such as list dict. Value = value. encode ( ' UTF-8  '  ) Citylist = Self. _ Secitydict  [Value] self.  _ Citycombobox  . Setitems (citylist) self.  _ Citycombobox  . Setvalue (citylist [0])  Def  Main (): app = Wx. pysimpleapp () comboboxframe (). Show () app. mainloop ()  If   _ Name __ = '  _ Main __  '  : Main () 

 

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.