[Solved]Mouse over problem in wxpython

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
buteman
Level 3
Level 3
Posts: 184
Joined: Tue Nov 29, 2011 5:36 pm
Location: North Lincolnshire

[Solved]Mouse over problem in wxpython

Post by buteman » Thu Feb 22, 2018 8:37 am

I am trying to develop a program for an elderly blind friend who used to love reading her Bible before she became blind. I am trying to develop it using wxpython on my Mint 18.2 laptop with python 3.5.2 installed. I have been shown a skeleton program and am part way through getting it working Here is the code so far

Code: Select all

class MouseEventFrame(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, 'Frame and Button', size=(1210, 400))
        self.panel = wx.Panel(self)
        row = 0
        column = 0
  
        for x in range(1,67):
            txt = books[x]
            myname = txt[0]
            while (len(myname) < 15):
               myname = " " + myname
            while (len(myname) < 20):
                myname += " "
            btn = 'butt' + str(x)
            btn = wx.Button(self.panel, -1, myname, pos=(column, row ) )
            self.Bind(wx.EVT_BUTTON, self.OnClick,btn)
            self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow,btn)
            column += 120
            if column == 1200:
                column = 0
                row += 55
    def OnClick(self, event):
       obj = event.GetEventObject()
       print("You clicked %s"%obj.GetLabel())
       event.Skip()       

    def OnEnterWindow(self, event):
        obj = event.GetEventObject()
        print("Success at last!")
        event.Skip()
The OnClick works but nothing happens with the OnEventWindow function.
There is no error generated and the print doesn't do anything either.
I keep thinking I have something but cannot see what.
I hope someone's eyes and brain are sharper than mine.
If I can get the second function working rather than a print I will try to get it to speak the text on the button so she knows what she is hovering the muse over.
tia
Norman
Last edited by buteman on Thu Feb 22, 2018 7:41 pm, edited 1 time in total.

buteman
Level 3
Level 3
Posts: 184
Joined: Tue Nov 29, 2011 5:36 pm
Location: North Lincolnshire

Re: Mouse over problem in wxpython

Post by buteman » Thu Feb 22, 2018 7:40 pm

I got the from a moderator on a python specific forum.
He suggested I change the

Code: Select all

self.Bind(wx.EVT_BUTTON, self.OnClick,btn)
self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow,btn)
to this

Code: Select all

btn.Bind(wx.EVT_BUTTON, self.OnClick,btn)
btn.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow,btn)
Which solved the problem.
Why the OnClick worked but not the other with the old settings is a puzzle

User avatar
all41
Level 13
Level 13
Posts: 4634
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: [Solved]Mouse over problem in wxpython

Post by all41 » Fri Feb 23, 2018 1:49 am

Hear my applause for your cause. :D
Proud to be a supporter and monthly contributor to Mint.

Post Reply

Return to “Software & Applications”