It has taken a few days to try, redo, restudy, try, redo, restudy repeatingly until just now ... after taken a corn and some snack ....
Here's a sample code ... of course I found the original code from google, and change here and there to get it work.
There are still a lot of things to learn and explore ... am trying to develop my own Project Scheduling Software ... I have started with Java 1.7, but found some bugs that reduce my confidence on it ... so try Python. Although it seems to be easier in syntax, but there are many ways for getting it work as per expected. But, still enjoy the problems ....
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 :)
Showing posts with label wxpython. Show all posts
Showing posts with label wxpython. Show all posts
Friday, July 11, 2014
Saturday, June 09, 2012
Sample Python Code: Showing Combobox Selected Text
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 :)
------------------------------------------------------------------------------------------------------------------------------
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 :)
Thursday, May 31, 2012
Useful wxPython Guides
Full reference: http://wxpython.org/docs/api/frames.html
Useful tutorials/guides with examples:
http://www.fredshack.com/docs/wxwidgets.html
http://www.java2s.com/Tutorial/Python/0380__wxPython/MDIframe.htm
http://www.blog.pythonlibrary.org/2008/05/18/a-wxpython-sizers-tutorial/
Useful tutorials/guides with examples:
http://www.fredshack.com/docs/wxwidgets.html
http://www.java2s.com/Tutorial/Python/0380__wxPython/MDIframe.htm
http://www.blog.pythonlibrary.org/2008/05/18/a-wxpython-sizers-tutorial/
Subscribe to:
Posts (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...
-
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...
-
This link shows why project management methodology is important. It also leads to the complete methodology of Tasmanian State Government .