The following code shows how to retrieve the selected text from wx.ComboBox when a mouse click event is triggered.
------------------------------------------------------------------------------------------------------------------------------
import wx
class MyFrame(wx.Frame):
def __init__(self, parent=None, id=-1, title=''):
wx.Frame.__init__(self, parent, id, title,size=(200, 240))
top = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
font = wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD)
lb = wx.StaticText(top, -1,'static text')
sizer.Add(lb)
c1 = wx.StaticText(top, -1, 'Number:')
self.s1 = c1.Label
c1.SetFont(font)
ct = wx.SpinCtrl(top, -1, '1', min=1, max=12)
sizer.Add(c1)
sizer.Add(ct)
c2 = wx.StaticText(top, -1, 'Type:')
c2.SetFont(font)
self.cb = wx.ComboBox(top, -1, '',choices=('A', 'B', 'C','D', 'E', 'F'))
sizer.Add(c2)
sizer.Add(self.cb)
showbtn = wx.Button(top)
showbtn.SetLabel('Show Info')
self.Bind(wx.EVT_BUTTON, self.ShowValue, showbtn)
sizer.Add(showbtn)
qb = wx.Button(top, -1, "QUIT")
self.Bind(wx.EVT_BUTTON,lambda e: self.Close(True), qb)
sizer.Add(qb)
top.SetSizer(sizer)
self.Layout()
def TestMe(val, self, e):
print val
def ShowValue(self, e):
wx.MessageBox('Show Value ...' + self.cb.GetStringSelection())
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(title="wxWidgets")
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp()
app.MainLoop()
--------------------------------------------------------------------------------------------------------------------------
Based on code above, the key part is to declare a self.cb variable to hold a reference to the combobox. This is the easiest way to refer to the combobox.
Of course, this is something I found after I have searched around and tried a few ways ... this is something I figure out when I don't find any specific example after googling :)
This blog captures some of the thoughts, ideas and things that am learning, researching and exploring on areas such as: Project Management, Software Development, Open Source, etc. Feel free to feedback or comment :)
Subscribe to:
Post Comments (Atom)
Converting a Physical Linux to Virtual
Hmm ... I have done a lot of work on my Linux Lubuntu 15.10 with PHP and PostgreSQL and a few other things ... it is quite time-consuming to...
-
I have got the book: Crucial Confrontation ! It is really a great book. After reading it, I learned a very valuable lesson on how to deal wi...
-
A requirement study stage should not be left "open-ended". There should be key review milestones specified for checking the accura...
-
Here are something to read about PM KPI: KPI explained When we want to create KPIs for PM, we need to use the CSC (Critical Success Criter...
No comments:
Post a Comment