Moms Who Code: Color Match Memory Game With Python + wxPython
- Ashley Kelly
- Jun 20
- 4 min read
Welcome back to Moms Who Code: Creative Projects for Life & Learning! If this is your first time here, I recommend starting with the introductory post where I explain the heart behind this series and who it's for (spoiler: busy, creative moms like you and me who want to build cool things with code).

This month, I’m so excited to share our very first project: a Color Match Memory Game that you can build using Python and wxPython. This is a perfect little intro project to get you comfortable working with graphical interfaces, and it’s simple enough to complete even if you only have short pockets of time here and there.
What We’re Building
This is a basic memory game where the player clicks on squares to reveal hidden colors and tries to find the matching pairs. The game tracks how many moves it takes to complete all matches. It’s a fun, interactive way to start learning how to code with a simple game that your young children can play.
Tools You’ll Need
Python 3.x (any recent version will do)
wxPython (you can install it with pip install wxPython)
A text editor or IDE you like (I personally love VSCode for this)
If you’re brand new to wxPython, don’t worry. You can go to this read my post about wxPython to read about how to get setup with a sample project before you start this one.
Coding Your Color Match Memory Game
We will start off by creating a 4 X 4 grid of buttons that hide colors underneath. When a player clicks a button, it shows the color. If two buttons match, they stay visible. If not, they flip back.
import wx # GUI library for making desktop apps
import random # Used to shuffle colors randomly
# Define the game window
class MemoryGame(wx.Frame):
def __init__(self):
# Set up the main game window
super().__init__(None, title="Color Match Memory Game", size=(400, 400))
# Add a panel to hold all the buttons
self.panel = wx.Panel(self)
# Create a 4x4 grid with 5px padding between buttons
self.grid = wx.GridSizer(4, 4, 5, 5)
# List of 8 colors, each appearing twice (total of 16 cards)
self.colors = ['red', 'blue', 'green', 'yellow',
'orange', 'purple', 'pink', 'cyan'] * 2
random.shuffle(self.colors) # Shuffle to mix them up
self.buttons = [] # Store the button widgets
self.revealed = [] # Keep track of revealed buttons
self.moves = 0 # Count how many turns have been taken
self.matched = [] # List of locked buttons to prevent matched cards from being reclicked
# Create and place 16 buttons into the grid
for i in range(16):
btn = wx.Button(self.panel, size=(80, 80))
btn.SetBackgroundColour(wx.Colour(200, 200, 200)) # Gray when hidden
btn.Bind(wx.EVT_BUTTON, self.on_click) # Set up click event
self.buttons.append(btn)
self.grid.Add(btn, 0, wx.EXPAND)
# Set the layout and show the game
self.panel.SetSizer(self.grid)
self.Show()
def on_click(self, event):
# Handle when a button is clicked
btn = event.GetEventObject()
idx = self.buttons.index(btn)
# Don't allow clicking if:
# - It's already matched
# - It's already revealed
if btn in self.matched or btn.GetBackgroundColour() != wx.Colour(200, 200, 200):
return
# Reveal the color behind the button
btn.SetBackgroundColour(self.colors[idx])
self.revealed.append((btn, self.colors[idx]))
# If two cards are revealed, check for a match
if len(self.revealed) == 2:
wx.CallLater(500, self.check_match) # Wait 500ms before checking
def check_match(self):
# Compare the two revealed buttons
btn1, color1 = self.revealed[0]
btn2, color2 = self.revealed[1]
self.moves += 1 # Increase move count
# If they don’t match, hide the colors again
if color1 != color2:
btn1.SetBackgroundColour(wx.Colour(200, 200, 200))
btn2.SetBackgroundColour(wx.Colour(200, 200, 200))
else:
self.matched.extend([btn1, btn2])
# Reset for next turn
self.revealed = []
# Check for winner
if len(self.matched) == len(self.buttons):
# Win message
wx.MessageBox(f"You won in {self.moves} moves!", "Congratulations")
# This part ensures the game runs when you run the script
if __name__ == '__main__':
app = wx.App(False)
frame = MemoryGame()
app.MainLoop()
What’s Happening in the Code?
Buttons are placed in a 4x4 grid with each hiding a color.
When a button is clicked, its color is revealed.
Two buttons at a time are compared. If the colors match, they stay revealed. If not, they go back to gray.
The game keeps track of how many moves the player has made.
Running Your Color Match Memory Game
Once the code is saved in a file (you can call it something like memory_game.py), run it by opening your terminal or command prompt and typing:
python memory_game.py
And just like that, you have your first game! Test it out to see how it runs, then try a few of the enhancements below.
Game Enhancements
Now that you’ve got a working and polished game, you could challenge yourself by adding some or all of the enhancements that I have listed before.
Add a restart button
Track and display time
Add emojis instead of colors
Let your child design the button graphics — make it a family coding-art collab!
Add Levels or Difficulty Modes and let your kiddo choose from Easy (4x4), Medium (5x5), or Hard (6x6) layouts — simply change the grid size and add more color pairs.
Offer fun themes like “Animals,” “Desserts,” “Under the Sea,” or “Outer Space.” Each theme could come with a different set of icons or color palettes.
This is a great little afternoon activity and helps teach them logic and sequencing in a playful way.
Final Coding Inspiration
I hope this first project inspires you to keep building things—even if it’s five minutes here, twenty minutes there. Coding doesn’t have to be all or nothing. Sometimes just making something small and fun can really spark joy and help us keep learning.
Let me know if you try it, or tag me if you share it online! I’d love to feature some of your projects in a future post. If you have any ideas for our next project in this series, then leave it below in the comments too.
Comments