Search code examples
pythontkinterpyqtwxpythonpygui

Use a mouse to draw on a screen with python?


I'd like to create a tool in python that I can use to draw things on my screen. I found one tool that does what I want, Epic Pen, but it's only supported on Windows and it doesn't have all the functionality I need. I was hoping someone could suggest a library that would could help me out with this project. Most of my Python work has been in research, and I haven't built any GUI's so I'm not really familiar with any libraries that could help me out. I'm sure there's more than one library that fits the bill. Which do you recommend? Why?

A few requirements/notes

  • I'd like for the tool to be completely cross platform (Linux/Mac/Windows)
  • I have to be able to draw things outside of a 'special' window. If I'm making a powerpoint presentation I'd like to be able to highlight or underline a key point. Or circle something on a picture etc.
  • I'd like to be able to get the position of the mouse on my screen and feed that back into the program.

Here's a link to a video showcasing the kind of tool I'd like to build


Solution

  • You will need to create a transparent widget that covers the screen so that you can draw on it. I don't know how each of the GUI toolkits does this, but I'm sure they all have the functionality necessary to grab the screen's size and create a window that can cover it. With wxPython, you would create a wx.Frame instance and call its SetTransparent method. You can see an example of that here:

    The wxPython demo includes a drawing demo that you might also want to take a look at.