wxython中List,ComboBox的使用

来源:互联网 发布:怎么加入淘宝联盟 编辑:程序博客网 时间:2024/05/20 05:55
#!/usr/bin/python
#-*- coding:utf8 -*-

#现在简单讲下List的使用

import wx

class ListFrame(wx.Frame):
    def __init__(self, root):
        wx.Frame.__init__(self, root, -1, u"下拉列表使用",size=(400, 300))
        panel = wx.Panel(self, -1)
        fruits = [u"橘子", u"香蕉", u"苹果", u"葡萄", u"梨子"]
        wx.StaticText(panel, -1, u"选择你最喜欢的水果",(10,10))
        self.listBox = wx.ListBox(panel, -1, (10,10), (80,110))
        self.listBox.SetSelection(0)  #默认选择第0项
        self.checkListBox = wx.CheckListBox(panel, -1, (100,10),(80,110), fruits, wx.LB_SORT)
        
        self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.listBox)
        self.string = []

        self.Bind(wx.EVT_CHECKLISTBOX, self.OnListBoxClick, self.checkListBox)

    def OnListBoxClick(self, event):
      #    for i in self.checkListBox.GetCheckedStrings():
      #           self.string.append(i)
        self.listBox.Append(self.checkListBox.GetStringSelection())
        

    def OnSelect(self, event):
        index = self.listBox.GetSelection()
        wx.MessageBox(self.listBox.GetString(index), u"提示")



class ComboBoxFrame(wx.Frame):
    def __init__(self, root):
        wx.Frame.__init__(self, root, -1, u"下拉列表", size=(400, 300))
        panel = wx.Panel(self, -1)
        fruits =[u"橘子", u"香蕉", u"苹果", u"葡萄", u"梨子"]
        wx.StaticText(panel,-1, u"喜欢的水果",(20,20))
        wx.ComboBox(panel, -1, u"香蕉", (100,20), wx.DefaultSize, fruits, wx.CB_DROPDOWN)


class MyApp(wx.App):
    def OnInit(self):
        self.frame = ComboBoxFrame(None)
        self.frame.Show()
        return True

app = MyApp()
app.MainLoop()

#这个小程序List部分还是有点问题  但是我也高不清楚哪里有问题


QQ交流群: 204944806

0 0