Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxEVT_ENTER_WINDOW doesn't call button SetBackgroundColour() #1960

Open
gunvald01 opened this issue May 9, 2021 · 3 comments
Open

wxEVT_ENTER_WINDOW doesn't call button SetBackgroundColour() #1960

gunvald01 opened this issue May 9, 2021 · 3 comments

Comments

@gunvald01
Copy link

Operating system: Windows 10, 20H2 build 19042.928
wxPython version & source: 4.1.1 pypi
Python version & source: 3.9.1 stock

Description of the problem:

Want to change button background color when mouse cursor is over the button to "yellow" and to "green" when mouse cursor is moved off of the button.

Using wx.EVT_ENTER_WINDOW to change button background color to "yellow" and wx.EVT_LEAVE_WINDOW to change background color to "green".

Below is simple code used to test behavior. Noticed that when mouse was over the button, background color didn't change to yellow but when mouse cursor was moved off of the button, background color changed to green as expected. Added SetLabel to display "INSIDE" when cursor was over the button to see if EVT_ENTER_WINDOW was getting fired. Running the code, found that INSIDE is displayed when cursor is over the button so EVT_ENTER_WINDOW is getting triggered but background color doesn't change. Moving cursor off of the button, OUTSIDE is displayed and button background color changes to green as expected. EVT_LEAVE_WINDOW event is working as expected. Since EVT_ENTER_WINDOW is fired, button background color should be yellow when cursor is over the button. Noticed that when cursor is over the button and left mouse button is down, button color changes to yellow and will remain yellow as long as left mouse button is held down. When lifted up, color changes to default color.

Code Example (click to expand)
    import wx
    def onMouseOverButton(event):
         btn.SetBackgroundColour("yellow")
         btn.SetLabel("INSIDE")

    def onMouseLeaveButton(event):
        btn.SetBackgroundColour("green")
        btn.SetLabel("OUTSIDE")

    app = wx.App()
    win = wx.Frame(None,size=(410,335))
    win.Show()
    btn = wx.Button(win,  pos=(50,50))
    btn.Bind(wx.EVT_ENTER_WINDOW,onMouseOverButton)
    btn.Bind(wx.EVT_LEAVE_WINDOW,onMouseLeaveButton)
    app.MainLoop()
@infinity77
Copy link
Contributor

I’d suggest adding btn.Refresh() in your mouse event handlers and see if it works.

@gunvald01
Copy link
Author

gunvald01 commented May 9, 2021

I’d suggest adding btn.Refresh() in your mouse event handlers and see if it works.

Thank you. Added btn.Refresh() to both handlers and didn't fix the issue.

@DietmarSchwertberger
Copy link
Contributor

I would suggest to close this issue.
See https://discuss.wxpython.org/t/cant-make-it-work-wx-button-setbackgroundcolour-on-wx-evt-enter-window/35272

Well, Windows 10 replaces the background colour with the light blue color when the button has the focus.

P.S.: Generic Buttons would probably be the best options. See the demo GenericButtons.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants