Python Mouse Trap with Source Code


Python Mouse Trap is a simple program which attracts a mouse with a cheese and then traps it in a cage. This project helps any user to play a game of mouse trap. Also, project is very simple and attractive with a language preference as python and library as sys, statemachine and many more.

Background Reading

Python Mouse Trap helps any user to build a game and a concept of catching a mouse. Similarly, classes has been made for better defining and making call in the function. So, waiting, luring, holding, trapping and mouseTrap classes are made. All  of these classes and functions are handled by mouseAction library.

Technology used

  • Python as a programming language.
  • Tkinter as a library for GUI based application.
  • Pycharm as an IDE.
  • pmw as a library.


  • Use of both mouse and keyboard to input numbers
  • Simple library with user understandable code.
  • Simple and easily understandable.
  • User-friendly game.
  • Command line game with one time run-able program.
  • Ease of use.
mouse trap test

mouse trap test


  1. A simple function starts with opening and closing of mouse trap.
  2. A loop function has been used for catching and removing a mouse.
  3. Also, a loop of cheese presenting and broad casting is done.
  4. Similarly, a function calls for a mouse and attracts it with a cheese and catch it.

Therefore things to know

  • You have to download python 2 or python 3 (sudo apt-get install python3).
  • So, you have to install pip or pip3 for downloading different libraries (sudo apt-get install python-pip).
  • Also, you can install Tkinter library with sudo pip install tkinter.
  • Likewise, you can install pycharm or Atom or Sublime text for an IDE or you can simply ~ sudo nano filename.
  • You have to install statemachine library with sudo pip install statemachine.

Therefore click on below button to download this project

Thank you,

0 0 vote
Article Rating

You may also like...

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x