Python Turtle Colors: Full Colors List, RGB, Hex and colormode

Python Turtle colors: chart of 147 named colours plus hex, RGB, colormode, random colours and gradients

Python Turtle accepts colours in three forms: a name such as “tomato”, a hex code such as “#1e90ff”, or an RGB tuple such as (46, 139, 87). Set the line colour with pencolor(), the fill with fillcolor(), both at once with color(), and the window with screen.bgcolor(). Below is the full chart of the 147 … Read more >>

How to Divide Two Numbers in Python (Program + Algorithm)

Divide two numbers in Python: 17 / 5, 17 // 5, 17 % 5 and divmod(17, 5) with results

To divide two numbers in Python, use the / operator: 17 / 5 gives 3.4. Use // for the whole-number part of the result, % for the remainder, and divmod() to get both at once. Below you’ll find a complete program that reads two numbers from the user, the algorithm and flowchart for it, and … Read more >>

Tkinter Drag and Drop: Widgets, Canvas, Lists and Files (tkinterdnd2)

Python Tkinter drag and drop: canvas items dragged into a basket and files dropped on a Treeview with tkinterdnd2

Drag and drop in Tkinter means one of two things, and they need different tools. Moving things inside your window (widgets, Canvas shapes, list rows) needs only mouse events: <ButtonPress-1>, <B1-Motion> and <ButtonRelease-1>. Dropping files from Explorer or Finder (or dragging data out to other programs) needs the tkinterdnd2 package, because plain Tkinter cannot receive … Read more >>

How to Read a Binary File into a Byte Array in Python

Read a binary file into a byte array in Python with bytearray and Path.read_bytes()

To read a binary file into a byte array in Python, use bytearray(Path(“file.bin”).read_bytes()), or open the file in “rb” mode and wrap f.read() in bytearray(). read() gives you immutable bytes; bytearray is the mutable version you can change and write back. This guide also covers reading byte by byte, reading large files in chunks, readinto(), … Read more >>

How to Draw Letters with Python Turtle (A–Z Function + Any Word)

Python Turtle draw letters: the alphabet A to Z drawn with a reusable letter function

To draw letters with Python Turtle, move the turtle between the corner points of each letter with goto(), lifting the pen with penup() between strokes. This guide starts with one letter, then builds a small reusable “stroke font” for all 26 capital letters, so you can draw any word, centre it, colour it, and compare … Read more >>

Python Turtle Font: Change Font, Size and Style (+ Fonts List)

Python Turtle font guide: a chart of twelve fonts written with turtle.write()

To change the font in Python Turtle, pass a font tuple to write(): pen.write(“Hello”, font=(“Arial”, 24, “bold”)). The tuple holds the font family, the size and the style. This guide shows every part of that tuple with a screenshot, how to list the fonts you can use on your computer, and how to align, measure, … Read more >>

Happy Birthday Code in Python (9 Programs with Output)

Happy birthday code in Python: 9 programs with output, shown with a Python Turtle birthday cake drawing

The shortest happy birthday code in Python is a single print() call with an f-string. Below you will find nine complete programs, from that one-liner to an ASCII-art banner, a text cake, a coloured and an animated terminal message, a Turtle drawing of a cake and a clickable Tkinter birthday card. Every program includes its … Read more >>