免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1479 | 回复: 0
打印 上一主题 下一主题

Core Windows/Controls → ComboBox [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-19 18:56 |只看该作者 |倒序浏览
Overview = """\

A ComboBox is like a combination of an edit control and a listbox. It can be
displayed as static list with editable or read-only text field; or a drop-down
list with text field; or a drop-down list without a text field.
Normally, ComboBox have be created for read-only controls. Meanwhile it can be
dynamically created (that is, it is initially empty but then we 'grow' it out of
program-supplied data).
Finally, this demo shows how event handling can differ.
EVT_TEXT_ENTER events, in which text is typed in and then ENTER is hit by the user.
EVT_TEXT can also be processed, but in that case the event is generated every time
that the user hits a key in the ComboBox entry field.

"""


import wx


class Frame(wx.Frame):
def __init__(
  self, parent, id=-1, title='ComboBox', pos=wx.DefaultPosition,
  size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
  ):
  
  wx.Frame.__init__(self, parent, id, title, pos, size, style)
  self.SetIcon(wx.Icon('wxWidgets.ico', wx.BITMAP_TYPE_ICO))
  
  
  Panel = wx.Panel(self, -1)
  wx.StaticText(Panel, -1, "wx.ComboBox control", (8, 10))
  wx.StaticText(Panel, -1, "Select one:", (15, 50), (75, 18))
  
  Languages = ['C', 'C++', 'Java', 'Perl', 'Ruby']
  ComboBox = wx.ComboBox(Panel, -1, 'Please Select', (90, 50), (95, -1),
          Languages, wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER)
  self.Bind(wx.EVT_COMBOBOX, self.OnComboBox, ComboBox)
  self.Bind(wx.EVT_TEXT, self.OnText, ComboBox)
  self.Bind(wx.EVT_TEXT_ENTER, self.OnTextEnter, ComboBox)
  
  # Append one item which has some client data
  ComboBox.Append('Python', 'I Like Zone Of Python!')
        
        
def OnComboBox(self, event):
  ComboBox = event.GetEventObject()
  ClientData = ComboBox.GetClientData(event.GetSelection())
  wx.MessageBox('You selected %s with client data: %s'% (event.GetString(), ClientData), 'Prompt')
  
  
def OnText(self, event):
  pass
  # wx.MessageBox('You input %s' % event.GetString(), 'Prompt')
  

# wx.TE_PROCESS_ENTER
# Capture events when the user types something into the control then
# hits ENTER.
def OnTextEnter(self, event):
  wx.MessageBox('You typed %s' % event.GetString(), 'Prompt')
  


def TestFrame():
app = wx.PySimpleApp()
frame = Frame(parent=None)
frame.Centre()
frame.Show()
app.MainLoop()


if __name__ == '__main__':
TestFrame()


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/35936/showart_281852.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP