How to Add an Image to Python Turtle (GIF, PNG and Background)

Attach an image to Python Turtle: rocket image shapes rotated in eight directions

To attach an image to a Python Turtle, register the image as a shape with screen.register_shape(“rocket.gif”) and then call t.shape(“rocket.gif”). Up to Python 3.13 that shortcut only accepts GIF files; PNG works too, but through tkinter.PhotoImage (shown below), and Python 3.14 adds PNG to register_shape() directly. This guide also covers background images, resizing, making images … Read more >>

PyQt6 QTreeView Tutorial: Examples with Models, Files, Checkboxes and Search

PyQt6 QTreeView tutorial: file browser with QFileSystemModel and checkable tree

QTreeView shows hierarchical data (folders, categories, parent/child records) as an expandable tree. It displays a model: the quickest is QStandardItemModel, where you add QStandardItem rows under other items. This guide builds working PyQt6 tree views step by step: a basic tree, a tree from a nested dict, a file browser, checkboxes, search, a context menu, … Read more >>

scipy.stats.multivariate_normal: pdf, cdf, rvs and fit (With Examples)

scipy.stats.multivariate_normal tutorial: pdf, cdf, rvs, fit and marginal with tested examples

scipy.stats.multivariate_normal is SciPy’s multivariate normal (Gaussian) distribution. Give it a mean vector and a covariance matrix, then call pdf() for the density, cdf() for probabilities, rvs() for random samples and fit() to estimate the parameters from data. This guide explains each method with a complete, runnable example and checks the results against simulation. Every example … Read more >>

Draw a Flower in Python Turtle: 6 Flower Programs with Code

Draw a flower in Python Turtle: sunflower and colourful flower drawn with Turtle code

To draw a flower with Python Turtle, draw one petal with two arcs (circle(radius, angle) twice, turning 180 – angle after each), then repeat it in a loop, turning 360 / petals degrees between petals. This page explains that petal trick with a diagram and then gives six complete flower programs to copy: a simple … Read more >>

Matplotlib savefig() Saves a Blank Image? 7 Causes and Fixes

Matplotlib plt.savefig saves a blank image: save before plt.show() or use fig.savefig()

plt.savefig() saves a blank image when the figure it saves is no longer the one you drew on. The most common reason is calling it after plt.show(): when you close the plot window, Matplotlib closes the figure, and plt.savefig() then saves a brand-new empty one. The fix is to save first, or to keep the … Read more >>

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 >>