DEV Community

Mate Technologies
Mate Technologies

Posted on

Building a Python Puzzle Studio with Tkinter: SixSeven Studio (Step-by-Step)

In this tutorial, we’ll build SixSeven Studio — a desktop puzzle generator written in Python.

By the end, you’ll have an app that:

Displays a modern Tkinter GUI

Generates logic puzzles

Exports layered SVG files

Creates barcodes

Saves and loads puzzles as JSON

This guide is beginner-friendly and breaks everything into small steps.

✅ Prerequisites

You’ll need:

Python 3.9+

Basic Python knowledge

pip installed

Step 1 — Install Dependencies

Open a terminal and run:

pip install ttkbootstrap svgwrite python-barcode pillow

These libraries provide:

ttkbootstrap → modern Tkinter UI

svgwrite → SVG export

python-barcode → barcode images

pillow → image handling

Step 2 — Create Your Project File

Create a new file:

sixseven_studio.py

Start with imports:

import tkinter as tk
from tkinter import filedialog, messagebox, colorchooser
import ttkbootstrap as tb
from pathlib import Path
import random
import svgwrite
from barcode import EAN13, Code128
from barcode.writer import ImageWriter
import json
import os
Enter fullscreen mode Exit fullscreen mode

Each module handles a different feature:

Tkinter → GUI

svgwrite → vector export

barcode → barcode creation

json → save/load puzzles

Step 3 — Create the Main Application Class

Now define your app:

class SixSevenStudioV5:
    def __init__(self):
        self.APP_NAME = "SixSeven Studio"
        self.APP_VERSION = "v5"

        self.root = tk.Tk()
        tb.Style(theme="darkly")

        self.root.title(f"{self.APP_NAME} {self.APP_VERSION}")
        self.root.geometry("1100x750")
Enter fullscreen mode Exit fullscreen mode

This initializes:

The main window

Dark theme

Title and size

Step 4 — App State Variables

Add these inside init:

self.style = tk.StringVar(value="Default")
self.puzzle = tk.StringVar(value="Futoshiki")
self.count = tk.IntVar(value=1)
self.grid_size = tk.IntVar(value=6)

self.bg_color = tk.StringVar(value="#222222")
self.accent_color = tk.StringVar(value="#4caf50")
self.font_size = tk.IntVar(value=24)

self.barcode_type = tk.StringVar(value="EAN13")
self.grid = []
Enter fullscreen mode Exit fullscreen mode

These variables connect your UI controls to logic.

Step 5 — Build the User Interface

Create a method:

def build_ui(self):
    tb.Label(self.root, text=self.APP_NAME,
             font=("Segoe UI", 22, "bold")).pack(pady=10)
Enter fullscreen mode Exit fullscreen mode

This shows the app title.

Options Panel

opts = tb.Labelframe(self.root, text="Options", padding=10)
opts.pack(fill="x", padx=10)
Enter fullscreen mode Exit fullscreen mode

Add puzzle selection:

tb.Label(opts, text="Puzzle Type:").pack(side="left")
tb.Combobox(
    opts,
    values=["Futoshiki","Arukone","Hidato","Tents & Trees","No-Four-In-Row"],
    textvariable=self.puzzle,
    width=20
).pack(side="left", padx=5)

Control Buttons
ctrl = tb.Frame(self.root)
ctrl.pack(fill="x", padx=10, pady=10)

tb.Button(ctrl, text="Generate",
          command=self.generate).pack(side="left")

tb.Button(ctrl, text="Export SVG",
          command=self.export_svg).pack(side="left", padx=5)
Enter fullscreen mode Exit fullscreen mode

Each button calls a method.

Step 6 — Displaying the Puzzle Grid

Create a grid container:

self.grid_frame = tb.Labelframe(self.root, text="Puzzle Grid", padding=10)
self.grid_frame.pack(fill="both", expand=True)
Enter fullscreen mode Exit fullscreen mode

Then render cells:

def display_grid(self):
    for w in self.grid_frame.winfo_children():
        w.destroy()

    size = self.grid_size.get()

    for r in range(size):
        for c in range(size):
            tb.Label(
                self.grid_frame,
                text=str(self.grid[r][c]),
                width=4,
                relief="ridge"
            ).grid(row=r, column=c, padx=2, pady=2)
Enter fullscreen mode Exit fullscreen mode

This redraws the grid every time puzzles change.

Step 7 — Simple Puzzle Generation

Example: No-Four-In-Row:

def generate_no_four(self, size):
    grid = []
    for r in range(size):
        row = []
        for c in range(size):
            options = [6, 7]
            if len(row) >= 3 and all(x == row[-1] for x in row[-3:]):
                options.remove(row[-1])
            row.append(random.choice(options))
        grid.append(row)
    return grid
Enter fullscreen mode Exit fullscreen mode

This prevents four identical values in a row.

Main generator:

def generate(self):
    size = self.grid_size.get()

    if self.puzzle.get() == "No-Four-In-Row":
        self.grid = self.generate_no_four(size)
    else:
        self.grid = [[random.choice([6,7,""]) for _ in range(size)] for _ in range(size)]

    self.display_grid()
Enter fullscreen mode Exit fullscreen mode

Step 8 — Exporting SVG Files

def export_svg(self):
    folder = filedialog.askdirectory()
    if not folder:
        return
Enter fullscreen mode Exit fullscreen mode

Create drawing:

dwg = svgwrite.Drawing("puzzle.svg", size=("700","800"))
Enter fullscreen mode Exit fullscreen mode

Add background:

dwg.add(dwg.rect((0,0),("100%","100%"), fill=self.bg_color.get()))
Enter fullscreen mode Exit fullscreen mode

Draw grid and numbers:

for r in range(size):
    for c in range(size):
        dwg.add(dwg.text(str(self.grid[r][c]),
                insert=(100+c*80,100+r*80)))
Enter fullscreen mode Exit fullscreen mode

Save:

dwg.save()

Step 9 — Barcode Generation
def generate_barcode(self):
    code = "".join(str(random.randint(0,9)) for _ in range(12))
    barcode = EAN13(code, writer=ImageWriter())
    barcode.save("barcode")
Enter fullscreen mode Exit fullscreen mode

This creates a scannable barcode image.

Step 10 — Save & Load Puzzles

Save:

with open("puzzle.json","w") as f:
    json.dump(self.grid,f)
Enter fullscreen mode Exit fullscreen mode

Load:

with open("puzzle.json","r") as f:
    self.grid = json.load(f)
Enter fullscreen mode Exit fullscreen mode

Step 11 — Run the App

Finally:

if __name__ == "__main__":
    SixSevenStudioV5().root.mainloop()
Enter fullscreen mode Exit fullscreen mode

🎉 Done!

You’ve built a desktop puzzle studio with:

Tkinter GUI

Logic puzzle generators

SVG export

Barcode creation

JSON persistence

Full source:

👉 https://github.com/rogers-cyber/SixSevenStudio

Ideas for Extensions

Add PDF export

Add difficulty levels

Improve puzzle algorithms

Add solution generation

Package with PyInstaller

Top comments (0)