Note that there are some explanatory texts on larger screens.

plurals
  1. POwxPython : Problem updating background color of controls
    text
    copied!<p>[EDIT - Reduced and re-posted code, restated question]</p> <p>I would like to change the background color of a frame (or panel; whichever makes it work). The problem is that the background color of controls on that frame (or panel) don't have their background color updated until I click on the control (the slider control, specifically).</p> <p>Any ideas on how to fix this?</p> <p>Here's some demo code:</p> <pre><code>import wx class MyFrame(wx.Frame): def __init__(self, *args, **kwds): kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.panel_1 = wx.Panel(self, -1) self.sliderDarken = wx.Slider(self.panel_1, -1, 206, 0, 255) self.label_3 = wx.StaticText(self.panel_1, -1, "This slider should darken the main panel.\n") self.btnPopup = wx.Button(self.panel_1, -1, "This button will pop up a dialog to dim the panel.") self.__set_properties() self.__do_layout() self.Bind(wx.EVT_COMMAND_SCROLL, self.onDarken, self.sliderDarken) self.Bind(wx.EVT_BUTTON, self.onDialogPopup, self.btnPopup) def __set_properties(self): self.SetTitle("Main Frame") def __do_layout(self): sizer_1 = wx.BoxSizer(wx.VERTICAL) sizer_3 = wx.BoxSizer(wx.HORIZONTAL) sizer_3.Add(self.sliderDarken, 0, 0, 0) sizer_3.Add(self.label_3, 0, 0, 0) sizer_3.Add(self.btnPopup, 0, 0, 0) self.panel_1.SetSizer(sizer_3) sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0) self.SetSizer(sizer_1) sizer_1.Fit(self) self.Layout() def onDarken(self, event): self.panel_1.SetBackgroundColour(wx.Colour(self.sliderDarken.GetValue(),self.sliderDarken.GetValue(),self.sliderDarken.GetValue())) self.panel_1.Refresh() def onDialogPopup(self, event): dlgPopup=MyDialog1(None) dlgPopup.Show() class MyDialog1(wx.Dialog): def __init__(self, *args, **kwds): kwds["style"] = wx.DEFAULT_DIALOG_STYLE wx.Dialog.__init__(self, *args, **kwds) self.sliderDarkenPopup = wx.Slider(self, -1, 206, 0, 255, style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_LABELS) self.label_2 = wx.StaticText(self, -1, "This slider should darken the panel on the main frame.") self.__set_properties() self.__do_layout() self.Bind(wx.EVT_COMMAND_SCROLL, self.onDarkenPopup, self.sliderDarkenPopup) def __set_properties(self): self.SetTitle("Dimmer Pop up") def __do_layout(self): sizer_2 = wx.BoxSizer(wx.HORIZONTAL) sizer_2.Add(self.sliderDarkenPopup, 0, 0, 0) sizer_2.Add(self.label_2, 0, 0, 0) self.SetSizer(sizer_2) sizer_2.Fit(self) self.Layout() def onDarkenPopup(self, event): frame_1.panel_1.SetBackgroundColour(wx.Colour(self.sliderDarkenPopup.GetValue(),self.sliderDarkenPopup.GetValue(),self.sliderDarkenPopup.GetValue())) frame_1.panel_1.Refresh() if __name__ == "__main__": app = wx.PySimpleApp(0) wx.InitAllImageHandlers() frame_1 = MyFrame(None, -1, "") app.SetTopWindow(frame_1) frame_1.Show() app.MainLoop() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload