Skip to main content

A lightweight Python library for creating animated, live-updating line charts natively in CustomTkinter — the modern dark-mode Tkinter framework.

Project description

Chinese

ctkchart

A Python library for creating live-updating line charts in CustomTkinter.

PyPI version

Downloads Downloads last 6 month Downloads/Month Downloads/Week

License: MIT


🎥 Watch the Main Demo Video on GitHub


✨ Features

Feature Description
Live Updates Stream and display real-time data continuously
📉 Multiple Lines Plot several lines on the same chart for easy comparison
🎨 Color Customization Tailor colors to match your app's design
🌓 Dynamic Theme Dynamic color change for dark & light themes
🔤 Font Customization Adjust text fonts for better readability
📐 Dimension Control Resize charts to fit any layout
🎛️ Granular Config Fine-grained control via configure_*() methods (v2.2.0+)

📋 See what's new in the latest release →


📦 Installation

pip install ctkchart
import ctkchart

🚀 Quick Start

import customtkinter as ctk
import ctkchart
import random
import threading
import time

root = ctk.CTk()

# 1. Create the chart
chart = ctkchart.CTkLineChart(
    master=root,
    x_axis_values=("a", "b", "c", "d", "e", "f"),
    y_axis_values=(100, 900)
)
chart.place(x=10, y=10)

# 2. Create a line
line = ctkchart.CTkLine(master=chart)

# 3. Stream data in a background thread
def loop():
    while True:
        chart.show_data(line=line, data=[random.choice(range(100, 900))])
        time.sleep(1)

threading.Thread(target=loop, daemon=True).start()
root.mainloop()

🎬 Live Examples

1 — Simple

▶️ View Simple Demo Video on GitHub

View code
import customtkinter as ctk
import ctkchart
import random
import threading
import time

root = ctk.CTk()
root.configure(fg_color="#0d1117")
root.geometry("720x430+200+200")

line_chart = ctkchart.CTkLineChart(
    master=root,
    x_axis_values=("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07", "01-08", "01-09", "01-10"),
    y_axis_values=(0, 1000)
)
line_chart.pack(pady=15)

line = ctkchart.CTkLine(master=line_chart)

def display_data():
    while True:
        line_chart.show_data(line=line, data=[random.choice(range(0, 1000))])
        time.sleep(0.5)

threading.Thread(target=display_data, daemon=True).start()
root.mainloop()

2 — Styled & Filled Line

▶️ View Styled & Filled Line Demo Video on GitHub

View code
import customtkinter as ctk
import ctkchart
import random
import threading
import time

root = ctk.CTk()
root.configure(fg_color="#0d1117")
root.geometry("720x430+200+200")

line_chart = ctkchart.CTkLineChart(
    master=root,
    x_axis_values=("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07", "01-08", "01-09", "01-10"),
    y_axis_values=(0, 1000),
    y_axis_label_count=10,
)
line_chart.pack(pady=15)

line = ctkchart.CTkLine(
    master=line_chart,
    size=2,
    fill="enabled"
)

def display_data():
    while True:
        line_chart.show_data(line=line, data=[random.choice(range(0, 1000))])
        time.sleep(0.5)

threading.Thread(target=display_data, daemon=True).start()
root.mainloop()

3 — 2 Lines with Different Styles

▶️ View 2 Lines Demo Video on GitHub

View code
import customtkinter as ctk
import ctkchart
import random
import threading
import time

root = ctk.CTk()
root.configure(fg_color=("#ffffff", "#0d1117"))
root.geometry("720x430+200+200")

line_chart = ctkchart.CTkLineChart(
    master=root,
    x_axis_values=("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07", "01-08", "01-09", "01-10"),
    y_axis_values=(0, 1000),
    y_axis_label_count=10,
)
line_chart.pack(pady=15)

line1 = ctkchart.CTkLine(
    master=line_chart,
    color=("#5dffb6", "#5dffb6"),
    size=2,
    style="dashed",
    style_type=(10, 5),
)

line2 = ctkchart.CTkLine(
    master=line_chart,
    color=("#FFBAD2", "#FFBAD2"),
    size=2,
    point_highlight="enabled",
    point_highlight_color=("#FFBAD2", "#FFBAD2"),
)

def display_data():
    while True:
        line_chart.show_data(line=line1, data=[random.choice(range(0, 1000))])
        line_chart.show_data(line=line2, data=[random.choice(range(0, 1000))])
        time.sleep(0.5)

threading.Thread(target=display_data, daemon=True).start()
root.mainloop()

4 — 3 Lines with Different Styles

▶️ View 3 Lines Demo Video on GitHub

View code
import customtkinter as ctk
import ctkchart
import random
import threading
import time

root = ctk.CTk()
root.configure(fg_color=("#ffffff", "#0d1117"))
root.geometry("720x430+200+200")

line_chart = ctkchart.CTkLineChart(
    master=root,
    x_axis_values=("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07", "01-08", "01-09", "01-10"),
    y_axis_values=(0, 1000),
    y_axis_label_count=10,
)
line_chart.pack(pady=15)

line1 = ctkchart.CTkLine(master=line_chart, size=2, fill="enabled")

line2 = ctkchart.CTkLine(
    master=line_chart,
    color=("#5dffb6", "#5dffb6"),
    size=2,
    style="dashed",
    style_type=(10, 5),
)

line3 = ctkchart.CTkLine(
    master=line_chart,
    color=("#FFBAD2", "#FFBAD2"),
    size=2,
    point_highlight="enabled",
    point_highlight_color=("#FFBAD2", "#FFBAD2"),
)

def display_data():
    while True:
        line_chart.show_data(line=line1, data=random.choices(range(0, 1000), k=1))
        line_chart.show_data(line=line2, data=random.choices(range(0, 1000), k=1))
        line_chart.show_data(line=line3, data=random.choices(range(0, 1000), k=1))
        time.sleep(0.5)

threading.Thread(target=display_data, daemon=True).start()
root.mainloop()

5 — With Grid Sections

▶️ View Grid Sections Demo Video on GitHub

View code
import customtkinter as ctk
import ctkchart
import random
import threading
import time

root = ctk.CTk()
root.configure(fg_color=("#ffffff", "#0d1117"))
root.geometry("720x430+200+200")

line_chart = ctkchart.CTkLineChart(
    master=root,
    x_axis_values=("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07", "01-08", "01-09", "01-10"),
    y_axis_values=(0, 1000),
    y_axis_label_count=10,
    y_axis_section_count=10,
    x_axis_section_count=10,
)
line_chart.pack(pady=15)

line1 = ctkchart.CTkLine(
    master=line_chart,
    color=("#5dffb6", "#5dffb6"),
    size=2,
    style="dashed",
    style_type=(10, 5),
)

line2 = ctkchart.CTkLine(
    master=line_chart,
    color=("#FFBAD2", "#FFBAD2"),
    size=2,
    point_highlight="enabled",
    point_highlight_color=("#FFBAD2", "#FFBAD2"),
)

def display_data():
    while True:
        line_chart.show_data(line=line1, data=[random.choice(range(0, 1000))])
        line_chart.show_data(line=line2, data=[random.choice(range(0, 1000))])
        time.sleep(0.5)

threading.Thread(target=display_data, daemon=True).start()
root.mainloop()

6 — Light and Dark theme

For every parameter that involves color in ctkchart, you can provide either:

  • A single string representing the color.
  • A tuple of two strings where the first string represents the color for the light theme and the second string represents the color for the dark theme.

▶️ View Dynamic Theme Demo Video on GitHub


📚 Documentation

Explore all parameters, configuration methods, and advanced usage:


👥 Contributors

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

ctkchart-2.2.0.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

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

ctkchart-2.2.0-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file ctkchart-2.2.0.tar.gz.

File metadata

  • Download URL: ctkchart-2.2.0.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ctkchart-2.2.0.tar.gz
Algorithm Hash digest
SHA256 bddb2557e35388fb414bffb992c37d65293126398f45b63a61b1979d06f04c56
MD5 e928ac04c8e1d13716d3be5f00763e58
BLAKE2b-256 73b8c8f05c854cfb27705458d4f08c553425c7e9c7612ae13aafb9121b8045f7

See more details on using hashes here.

File details

Details for the file ctkchart-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: ctkchart-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ctkchart-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40398a04e1c27d4f90f540ab30a581acf16faa42516201109c7d15aa3bac7318
MD5 5639eb9244710706ab24c74a8214fb8c
BLAKE2b-256 f947c1beede5073898ef8d2c56e67eef2adfb72974fde6c01ac07914dbacf371

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