[Solved]Mouse over problem in wxpython

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
buteman
Level 4
Level 4
Posts: 331
Joined: Tue Nov 29, 2011 5:36 pm
Location: North Lincolnshire

[Solved]Mouse over problem in wxpython

Post by buteman »

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 LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
buteman
Level 4
Level 4
Posts: 331
Joined: Tue Nov 29, 2011 5:36 pm
Location: North Lincolnshire

Re: Mouse over problem in wxpython

Post by buteman »

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 19
Level 19
Posts: 9520
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: [Solved]Mouse over problem in wxpython

Post by all41 »

Hear my applause for your cause. :D
Everything in life was difficult before it became easy.
Locked

Return to “Software & Applications”