wxpython,Combox Choice用法

选项choices是一个数组,value是默认值

import wx
class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(parent=None,title="vbox",size=(600,150),pos=(100,100))   #继承wx.Frame类
        self.Center()
        panel = wx.Panel(parent=self)   #面板

        hbox1 = wx.BoxSizer(wx.HORIZONTAL)

        statictext = wx.StaticText(parent=panel,label='Which language do you like')
        list1=['C#','C++','java','python']
        ch1=wx.ComboBox(panel,-1,value='C#',choices=list1)
        self.Bind(wx.EVT_COMBOBOX,self.on_combox,ch1)
        hbox1.Add(statictext,1,flag=wx.LEFT | wx.RIGHT | wx.FIXED_MINSIZE)
        hbox1.Add(ch1,1,flag=wx.ALL | wx.EXPAND)

        hbox2 = wx.BoxSizer(wx.HORIZONTAL)

        statictext2 = wx.StaticText(parent=panel,label='sex')
        list2=['male','female']
        ch2=wx.Choice(panel,-1,choices=list2)
        self.Bind(wx.EVT_CHOICE,self.on_choice,ch2)
        hbox2.Add(statictext2,1,flag=wx.LEFT | wx.RIGHT | wx.FIXED_MINSIZE)
        hbox2.Add(ch2,1,flag=wx.ALL | wx.EXPAND)

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(hbox1,1,flag=wx.ALL | wx.EXPAND,border=5)
        vbox.Add(hbox2,1,flag=wx.ALL | wx.EXPAND,border=5)

        panel.SetSizer(vbox)

    def on_combox(self,event):
        print('choose1'+event.GetString())

    def on_choice(self,event):
        print('choose2'+event.GetString())

class App(wx.App):
    def OnInit(self):    #进入
        frame = MyFrame()
        frame.Show()
        return True
    def OnExit(self):   #退出
        print("tuichu")
        return 0

if __name__ == '__main__':
    app=App()
    app.MainLoop()

wxpython,Combox Choice用法_第1张图片在这里插入图片描述

你可能感兴趣的:(python)