help with getting selection from wxChoice with out after it has changed

?

'

I want to get the selection of several wxChoice boxes.
But i do not want to have to catch the events for all the boxes
I should be able to access the current selection outside of an
event,but i am not seeing how to do this.


This is a hack of the wxpython choice demo to demonstrate my question

#--------- comment marks are for indention
#import wx
#class TestChoice(wx.Dialog):
# def __init__(self, parent):
# #self.log = log
# wx.Dialog.__init__(self, parent, -1)
#
# sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
# 'six', 'seven', 'eight']
#
# wx.StaticText(self, -1, "This example uses the wxChoice
control.", (15, 10))
# wx.StaticText(self, -1, "Select one:", (15, 50), (75, -1))
# self.ch = wx.Choice(self, -1, (100, 50), choices = sampleList)
# self.Bind(wx.EVT_CHOICE, self.EvtChoice, self.ch)
#
#
# def EvtChoice(self, event):
# print('EvtChoice: %s\n' % event.GetString())
# self.ch.Append("A new item")
#
##-----changed here --------- from event.GetSelection()
# if self.ch.GetSelection() == 'one':
# print('Well done!\n')
#
#
#if __name__ == "__main__":
# app = wx.PySimpleApp(0)
# wx.InitAllImageHandlers()
# Dialog_Main = TestChoice(None)
# app.SetTopWindow(Dialog_Main)
# Dialog_Main.Show()
# app.MainLoop()
 
G

Gerrit Holl

'@'.join([..join(['fred' said:
From: "'@'.join([..join(['fred', 'dixon']), ..join(['gmail', 'com'])])" <[email protected]>

This is a SyntaxError.
You want to enclose the dots with '' marks as well, like this:

'@'.join(['.'.join(['fred', 'dixon']), '.'.join(['gmail', 'com'])])

regards,
Gerrit Holl.

--
Weather in Twenthe, Netherlands 29/03 10:55:
10.0°C mist overcast wind 0.9 m/s None (57 m above NAP)
--
In the councils of government, we must guard against the acquisition of
unwarranted influence, whether sought or unsought, by the
military-industrial complex. The potential for the disastrous rise of
misplaced power exists and will persist.
-Dwight David Eisenhower, January 17, 1961
 
P

Peter Otten

I want to get the selection of several wxChoice boxes.
But i do not want to have to catch the events for all the boxes
I should be able to access the current selection outside of an
event,but i am not seeing how to do this.
# def EvtChoice(self, event):
# print('EvtChoice: %s\n' % event.GetString())
# self.ch.Append("A new item")
#
##-----changed here --------- from event.GetSelection()
# if self.ch.GetSelection() == 'one':
# print('Well done!\n')

Perhaps you are confused by the fact that GetSelection() returns an integer?
Changing the above to either

if self.ch.GetStringSelection() == 'one':
print 'Well done!'

or

if self.ch.GetSelection() == 1:
print 'Well done, too!'

should work as you expect then.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top