In the attached little program, the command
line1.SetBackgroundColour(wx.LIGHT_GREY)
sets the background color of line1 when it’s part of the initialization but not when it’s called by clicking a button, though the command is exactly the same in each case. I can’t see why and I’d be grateful to anyone who can point out the reason.
Patrick Maher
http://patrick.maher1.net
test2.py (1.07 KB)
From what I can tell by playing around with the code, it works at
initialization because it's being created with the background set to
light_grey. To set the background after creation, in your code you
have to call 'textwin.Refresh()' after 'line1.SetBackgroundColour()'
in the 'makegrey' function.
Joseph.
···
On Sep 22, 3:23 pm, Patrick Maher <patr...@maher1.net> wrote:
In the attached little program, the command
line1\.SetBackgroundColour\(wx\.LIGHT\_GREY\)
sets the background color of line1 when it's part of the initialization but
not when it's called by clicking a button, though the command is exactly the
same in each case. I can't see why and I'd be grateful to anyone who can
point out the reason.
Patrick Maherhttp://patrick.maher1.net
test2.py
1KViewDownload
Joseph Wourms sent me the following, which solves the problem. Thanks Joseph!
<details class='elided'>
<summary title='Show trimmed content'>···</summary>
----------------------------------------------------
Sorry if this gets posted twice but this is my first time posting...
Don't know whether to hit reply or reply to author... anyway.
In your code, the reason it works in the __init__ method is because
it's being created with the background set to light_grey. In order to
set the background after creation you have to refresh the widget after
you set the background.
The modified code looks like this:
def makegrey(event):
line1.SetBackgroundColour(wx.LIGHT_GREY)
textwin.Refresh()
Hope this helps :)
Joseph