Skip to main content

Draw and interact with shapes on the Tkinter canvas

Project description

Tkinter Canvas Shapes

Note: This is a Python 3.6+ module.

The tkshapes module adds a GCanvas widget which can contain user-configurable shapes. The GCanvas widget supports the standard Tk canvas shapes, as well as some others useful in diagrams. (Not all implemented yet.)

  • GObjects can be constructed from GItems
  • GObjects are displayed on the GCanvas
  • GObjects can be dragged around individually, or selected and dragged together
  • GObjects can have GNodes
  • GNodes can be connected by a GConnection (visualized by a GWire)

Controls

The GCanvas Keyboard and Mouse controls are as follows:

  • Control + MouseClickHold-and-Drag or Two-finger swipe to Pan the canvas

  • Control + MouseWheel or Control + Two-finger Vertical swipe to Zoom In/Out

  • Click-Drag a single shape to move it around on the canvas

  • Command + Click to toggle selection of a single shape

  • Click-Drag on the canvas to mark out a Selection Box

    • Selected shapes can highlight themselves if configured to do so (default)
    • Click-Drag one of the selected shapes to move them all together
    • Click anywhere on the canvas to de-select all shapes
    • Command + Click individual shapes to add/remove shapes from the selected set (toggle)
  • To make a connection between two "Connectable" shapes:

    • Click and Hold on an "Output" Node of a shape (such as one of the Logic Gates in the Demo)
    • Begin to Drag and a wire will appear
    • Drag the wire to an "Input" Node of another shape and release to complete the connection

Installation

Create your Python 3.6+ virtual environment

python3.6 -m venv env

Activate your virtual env

source env/bin/activate

Install tkapp and tkshapes (The demo.py depends on the tkapp module as well.)

pip install tkapp tkshapes

Alpha - In-Development

This library is being developed so that I can use it to build a Digital Logic Simulator app. I wasn't able to find a Tkinter library that did what I need, so decided to try and write one from scratch.

At this time, the only documentation is this README, the code itself, as well as a demo.py which shows the basic usage.

I'm developing and testing ONLY on macOS.

Known Issues

  • when the Tkinter window is put in full-screen mode using the full-screen green dot button at the top left of the window, mouse position is incorrectly calculated. You'll notice that the calculated mouse position on the GCanvas is slightly off. This appears to be a Tkinter bug, but I'm not 100% sure. Instead of using full-screen mode, you may click Option-GreenDot to maximize the window to use the full screen without actually entering full-screen mode.

    FIXED: this issue has been fixed with Python 3.7 releases. I've tested both the standard CPython and Anaconda distributions, and this issue is no longer present. It appears that "Fullscreen Mode" simply does a window maximize now, automatically accomplishing the workaround mentioned above.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tkshapes-0.0.4.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tkshapes-0.0.4-py36-none-any.whl (50.4 kB view details)

Uploaded Python 3.6

File details

Details for the file tkshapes-0.0.4.tar.gz.

File metadata

  • Download URL: tkshapes-0.0.4.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for tkshapes-0.0.4.tar.gz
Algorithm Hash digest
SHA256 207a7375ed5e4f76a868c9612eb215a7e81c97201036e3577e988b3a7370c719
MD5 680b16e2d7393e333495b108bb855d6c
BLAKE2b-256 caad9e02dee252680e55c96e3e5d6f8b43cc5e18a42b801b5817a3a953a3294b

See more details on using hashes here.

File details

Details for the file tkshapes-0.0.4-py36-none-any.whl.

File metadata

  • Download URL: tkshapes-0.0.4-py36-none-any.whl
  • Upload date:
  • Size: 50.4 kB
  • Tags: Python 3.6
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for tkshapes-0.0.4-py36-none-any.whl
Algorithm Hash digest
SHA256 74b67d3505c866a7589c1f64417a6a65b0128aff99b68382ebdc2c8e4c8c88f0
MD5 a6797ece66c975c61449041596e231fd
BLAKE2b-256 674d6f8df1497a8d98b8fdc39b567f5f6534293451c5e08b00d9dd6da6872e6e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page