WxPython Tutorial to Get Mouse Screen Position Coordinates in Input Box Using MouseOver Event GUI Desktop App Full Project For Beginners

WxPython Tutorial to Get Mouse Screen Position Coordinates in Input Box Using MouseOver Event GUI Desktop App Full Project For Beginners

 

Welcome folks today in this blog post we will be displaying mouse screen position coordinates inside input textbox in wxpython gui  desktop app in python All the full source code of the application is given below.

 

 

Get Started

 

 

In order to get started you need to install the below library using the pip command as shown below

 

pip install wxpython

 

After installing this library you need to make an app.py file and copy paste the following code

 

app.py

 

#!/bin/env python
import wx

class MyFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, -1, "My Frame", size=(300, 300))
        panel = wx.Panel(self, -1)
        panel.Bind(wx.EVT_MOTION,  self.OnMove)
        wx.StaticText(panel, -1, "Pos:", pos=(10, 12))
        self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(40, 10))

    def OnMove(self, event):
        pos = event.GetPosition()
        self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = MyFrame()
    frame.Show(True)
    app.MainLoop()

 

See also  Join 30 Python Deep Learning Whatsapp Group Invite Links For Machine Learning and Arduino Developers in 2021-22

If you execute the above python script by typing the below command

 

python app.py

 

 

 

Now it will tell you the exact position of your mouse in terms of x and y coordinates inside the textbox

Leave a Reply