r/Tkinter

Tkinter has no built-in way to stream live data into a chart. So I built one.
▲ 10 r/Tkinter

Tkinter has no built-in way to stream live data into a chart. So I built one.

Tkinter has a solid set of widgets for building desktop GUIs, but if you need a chart that updates in real time — think monitoring dashboards, sensor feeds, live logs — you're mostly stuck reaching for matplotlib embedded in a canvas, which introduces a dependency and a non-trivial amount of boilerplate just to get a simple scrolling line.

I built tkchart to fill that gap. It's a pure-Python library (zero external dependencies) that adds a LineChart widget directly into Tkinter. You create a chart, attach Line objects to it, and call show_data() from a background thread. That's the full loop.

import tkinter as tk
import tkchart
import threading, time, random

root = tk.Tk()

chart = tkchart.LineChart(
    master=root,
    x_axis_values=("t-9", "t-8", "t-7", "t-6", "t-5", "t-4", "t-3", "t-2", "t-1", "t"),
    y_axis_values=(0, 1000),
    y_axis_section_count=5,
    x_axis_section_count=10,
)
chart.pack(pady=10)

line = tkchart.Line(master=chart, color="#5dffb6", size=2, fill="enabled")

def stream():
    while True:
        chart.show_data(line=line, data=[random.randint(0, 1000)])
        time.sleep(0.5)

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

A few things I spent time on:

  • Threading: show_data() is meant to be called from a non-main thread. Tkinter isn't thread-safe by default, so all canvas operations are marshalled back to the main loop carefully.
  • Multiple lines: You can layer several Line objects on the same LineChart, each with independent style (solid/dashed/dotted, fill, point highlights, custom colors).
  • Post-construction config: v2.2.0 added granular configure_*() methods so you can change axis colors, font styles, pointer behavior, etc. at runtime without rebuilding the widget.
  • Data retrieval: get_line_data(), get_lines_visible_data(), and friends let you query what's currently on screen — useful if you want to trigger alerts when a value crosses a threshold.

Install: pip install tkchart

GitHub: https://github.com/Thisal-D/tkchart

PyPI: https://pypi.org/project/tkchart/

What's the hardest part of building real-time data widgets in Tkinter for you? I'm curious whether the threading model is a dealbreaker for some use cases or if people just live with after() polling.

u/Fabulous-Tip-8007 — 11 days ago