Reputation: 11
Using wxwidgets with python, how do I bind an event to the listbox so that everytime a new list box entry is clicked, information about the list box entry is displayed in the textbox?
Here is my code:
import wx
from ConfigParser import *
class settings(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Frame aka window', size=(500,500))
panel=wx.Panel(self)
wx.StaticText(panel, -1, "Field Type:", pos=(200,20))
wx.TextCtrl(panel,-1,"",pos=(270,20))
for msg_num in self.ACTIVE_MESSAGES:
self.MESSAGE_FIELDS[msg_num] = configuration.get("MESSAGE_FIELDS", msg_num).replace(' ', '').split(',')
self.MESSAGE_FIELD_TYPES[msg_num] = configuration.get("MESSAGE_TYPES", msg_num).replace(' ', '').split(',')
cont=wx.ListBox(panel, -1, (20,20), (150,400), self.MESSAGE_FIELDS['1'], wx.LB_SINGLE)
cont.SetSelection(3)
if __name__=='__main__':
app=wx.PySimpleApp()
frame=settings(parent=None, id=-1)
frame.Show()
app.MainLoop()
Upvotes: 0
Views: 2206
Reputation: 11
This is the solution that I came up with:
import wx
from ConfigParser import *
class settings(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Frame aka window', size=(500,500))
panel=wx.Panel(self)
configuration = ConfigParser()
configuration.read('SerialReader.conf')
self.ACTIVE_MESSAGES = configuration.get("GENERAL_SETTINGS", "ACTIVE_MESSAGES").split(',')
self.fieldLabel = wx.StaticText(panel, -1, "Field Type:", pos=(200,20))
self.text = wx.TextCtrl(panel,-1,"",pos=(270,20))
self.MESSAGE_FIELDS = {}
self.MESSAGE_FIELD_TYPES = {}
for msg_num in self.ACTIVE_MESSAGES:
self.MESSAGE_FIELDS[msg_num] = configuration.get("MESSAGE_FIELDS", msg_num).replace(' ', '').split(',')
self.MESSAGE_FIELD_TYPES[msg_num] = configuration.get("MESSAGE_TYPES", msg_num).replace(' ', '').split(',')
cont=wx.ListBox(panel, 26, (20,20), (150,400), self.MESSAGE_FIELDS['1'], wx.LB_SINGLE)
cont.SetSelection(3)
self.Bind(wx.EVT_LISTBOX, self.OnSelect, id = 26)
def OnSelect(self, event):
index = event.GetSelection()
self.text.SetValue(self.MESSAGE_FIELD_TYPES['1'][index])
if __name__=='__main__':
app=wx.PySimpleApp()
frame=settings(parent=None, id=-1)
frame.Show()
app.MainLoop()
Upvotes: 1