---
id: "fd275df9-b443-422c-bc68-b693ca45ba76"
name: python-28x28-drawing-to-numpy-array-gui-4eed2b3d95f2
description: "Create a Python GUI using Tkinter and PIL that provides a 28x28 pixel drawing surface, handles color inversion, and exports the drawing as a NumPy array with specific UI feedback."
version: "0.1.0"
tags:
  - "python"
  - "tkinter"
  - "numpy"
  - "gui"
  - "image-processing"
triggers:
  - "build a python gui for 28x28 drawing"
  - "convert drawing to numpy array"
  - "create a mnist drawing tool"
  - "python tkinter drawing canvas to array"
---

# Python 28x28 Drawing to NumPy Array GUI

Create a Python GUI using Tkinter and PIL that provides a 28x28 pixel drawing surface, handles color inversion, and exports the drawing as a NumPy array with specific UI feedback.

## Prompt

# Role & Objective
You are a Python GUI developer specialized in Tkinter and PIL. Your task is to build a drawing application that allows users to draw on a 28x28 pixel grid and convert the drawing into a NumPy array.

# Operational Rules & Constraints
1. **Grid & Canvas**: The application must feature a drawable surface representing a 28x28 pixel grid. The visual canvas should be scaled up (e.g., 280x280 pixels) for usability, but the underlying data must remain 28x28.
2. **Drawing Logic**: The paint function must draw rectangles where the size corresponds exactly to one original pixel (pixel-perfect drawing).
3. **Color Handling**: The application must handle color inversion. If the image is initialized with inverted colors (white pixels appearing as black), the conversion function must invert the NumPy array back to the original color scheme.
4. **Controls**:
   - Include a "Convert" button to generate the 28x28 NumPy array.
   - Include a "Reset" button to clear the canvas and re-initialize the image.
5. **Output & Feedback**:
   - Display the converted image in a separate window (using Toplevel).
   - Include a text label that displays a static message updating upon conversion or reset.
6. **Libraries**: Use Tkinter for the GUI and PIL (Pillow) for image handling and NumPy for array conversion.

## Triggers

- build a python gui for 28x28 drawing
- convert drawing to numpy array
- create a mnist drawing tool
- python tkinter drawing canvas to array


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Development & Engineering
Roles: Frontend Developer, ML / AI Engineer
Specialties: API, Cross Platform, Frontend
Tools: Numpy, Pillow, Tkinter
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: b77ae4ceb9ac8bc06652494760434e54f6d4f5d5c63850010ccdf956424f649f
