[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Create a simple drawing app using the Python library "TKEasyGUI"

Hello
Interested and Curious
is Kawaii from the Volatile Systems Solutions Department.

It's already December this year.
The other day, I was playing around with a Python TKEasyGUI , and I heard that you can easily create desktop applications, so I decided to create a drawing application.

What is TKEasyGUI?

It seems to have been developed in response to the
PySimpleGUI For more information: https://github.com/kujirahand/tkeasygui-python

Preparation

Now, let's install it and play with it.

■Verification environment

Ubuntu 24.04 LTS Python 3.12.3

This time we will use venv. You can do anything you want in this area.

$ python3 -m venv env $ source env/bin/activate

TKEasyGUI and tkinter are also required, so install them.

(env)$ pip install TKEasyGUI (env)$ sudo apt install python3-tk

That's all you need to prepare. It's super easy.

Try the sample app

Now, let's run the sample app posted on github.
>> "How to use - popup dialogs"

import TkEasyGUI as eg name = eg.input("What is your name?") eg.print(f"Hello, {name}.")

 

(env)$ python3 question.py 

You will be asked for your name, so enter it.

They will greet you.

It's easy because you only have to write two documents except for import.
Next, let's create a simple drawing app.

drawing app.py

Anything is fine for now, so I'll make it possible to save it as a PNG, draw it easily, and select the color.
The following Canvas elements can be used for depiction.
https://github.com/kujirahand/tkeasygui-python/blob/main/docs/TkEasyGUI/widgets-py.md#canvas

the full code below
, if you want to run it, please try running it.

import TkEasyGUI as eg from tkinter import filedialog, colorchooser from PIL import Image, ImageDraw # Drawing settings drawing_color = "black" # Initial color last_x, last_y = None, None # Record last position # File save function def save_canvas_as_image(): file_path = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG file", "*.png")]) if file_path: canvas_image.save(file_path) eg.popup("Save completed", "Image saved.") # Color selection function def choose_color(): global drawing_color color_code = colorchooser.askcolor(title="Choose color") if color_code: drawing_color = color_code[1] # Get the hex code of the selected color # Draw function def start_draw(event): global last_x, last_y last_x, last_y = event.x, event.y def draw(event): global last_x, last_y x, y = event .x, event.y if last_x is not None and last_y is not None: # Draw a line on the canvas canvas.get().create_line(last_x, last_y, x, y, fill=drawing_color, width=2) # Also draw on PIL Image draw_on_image.line([last_x, last_y, x, y], fill=drawing_color, width=2) last_x, last_y = x, y # Clear function def clear_canvas(): canvas.clear() draw_on_image.rectangle((0, 0, 400, 400), fill="white") # Also reset the image # Layout definition layout = [ [eg.Text("Drawing app")], [eg.Canvas(key="-CANVAS-", size=(400, 400), background_color="white")], [eg.Button("Change color", key="-COLOR-"), eg.Button("Clear"), eg.Button("Save"), eg.Button("End")] ] # Create a PIL image and get the drawing object canvas_image = Image.new("RGB", (400, 400), "white") draw_on_image = ImageDraw.Draw(canvas_image) # Create a window with eg.Window("Drawing app", layout) as window: canvas = window["-CANVAS-"] # Bind mouse events canvas.get().bind("<Button-1> ", start_draw) canvas.get().bind("<B1-Motion> ", draw) # Event loop for event, values ​​in window.event_iter(): if event == "-COLOR-": choose_color() elif event == "Clear": clear_canvas() elif event == "Save": save_canvas_as_image() elif event == "End" or event is None: break

I'll try starting it.

(env)$ python oekaki.py 

A white canvas was displayed.

I'll try drawing a cat.

I'll try saving it.

You can also change the color.

Looks good,

I'll try making it again when I have time. Well then.

complete

If you found this article helpful , please give it a like!
7
Loading...
7 votes, average: 1.00 / 17
245
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author

Kawa Ken


A curious Poke○n who belongs to the System Solution Department.