Method onPaint does not change the color. Does anyone know why?
(there are no errors received)
# explore the wxChoice widget
# a simple ComboBox (dropdown box) that combines a ListBox with an EditBox
# can't get the self.onPaint method to work!!!!!
import wx
ID_CHOICE = 120
ID_PANEL = 130
class MyFrame(wx.Frame):
def __init__(self ):
wx.Frame.__init__(self, None, -1, 'wxChoice test', size=(250, 200))
self.panel = wx.Panel(self, ID_PANEL)
colorList = ['red', 'green', 'blue', 'yellow','white']
# create the dropdown box
self.choice = wx.Choice(self.panel, ID_CHOICE, choices=colorList)
# select item 1 = 'green' to show
self.choice.SetSelection(1)
self.bgcolor = self.choice.GetStringSelection()
self.panel.SetBackgroundColour(self.bgcolor)
# new event handler wxPython version 2.5 and higher
self.choice.Bind(wx.EVT_CHOICE, self.onChoice)
self.Bind(wx.EVT_PAINT, self.onPaint)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.choice, 0)
self.panel.SetSizerAndFit(self.sizer)
def onChoice(self, event):
'''get the selected color choice'''
self.bgcolor = self.choice.GetStringSelection()
self.SetTitle(self.bgcolor)
def onPaint(self, event):
'''update panel with the present color selection'''
self.panel.ClearBackground()
self.panel.SetBackgroundColour(self.bgcolor)
#self.panel.ClearBackground()
app = wx.App(0)
# create MyFrame instance and show
MyFrame().Show()
app.MainLoop()