Add a radial gauge to the widgets module
See original GitHub issueI’d like to include a widgets module with ttkbootstrap that includes custom widgets that are useful in modern UI’s.
This radial gauge is a potential candidate (example is in vanilla ttk). I can create it with theme colors, and I’ve set it up to be adjustable in the constructor. Though, I’d probably want the customization to the style class instead of using the constructor to be consistent with the ttk api, at least as much as possible.
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk, ImageDraw
class Gauge(ttk.Label):
def __init__(self, parent, **kwargs):
self.arc = None
self.im = Image.new('RGBA', (1000, 1000))
self.min_value = kwargs.get('minvalue') or 0
self.max_value = kwargs.get('maxvalue') or 100
self.size = kwargs.get('size') or 200
self.font = kwargs.get('font') or 'helvetica 12 bold'
self.background = kwargs.get('background')
self.foreground = kwargs.get('foreground') or '#777'
self.troughcolor = kwargs.get('troughcolor') or '#e0e0e0'
self.indicatorcolor = kwargs.get('indicatorcolor') or '#01bdae'
self.arcvariable = tk.IntVar(value='text')
self.arcvariable.trace_add('write', self.update_arcvariable)
self.textvariable = tk.StringVar()
self.setup()
super().__init__(parent, image=self.arc, compound='center', style='Gauge.TLabel',
textvariable=self.textvariable, **kwargs)
def setup(self):
"""Setup routine"""
style = ttk.Style()
style.configure('Gauge.TLabel', font=self.font, foreground=self.foreground)
if self.background:
style.configure('Gauge.TLabel', background=self.background)
draw = ImageDraw.Draw(self.im)
draw.arc((0, 0, 990, 990), 0, 360, self.troughcolor, 100)
self.arc = ImageTk.PhotoImage(self.im.resize((self.size, self.size), Image.LANCZOS))
def update_arcvariable(self, *args):
"""Redraw the arc image based on variable settings"""
angle = int(float(self.arcvariable.get())) + 90
self.im = Image.new('RGBA', (1000, 1000))
draw = ImageDraw.Draw(self.im)
draw.arc((0, 0, 990, 990), 0, 360, self.troughcolor, 100)
draw.arc((0, 0, 990, 990), 90, angle, self.indicatorcolor, 100)
self.arc = ImageTk.PhotoImage(self.im.resize((self.size, self.size), Image.LANCZOS))
self.configure(image=self.arc)
if __name__ == '__main__':
root = tk.Tk()
style = ttk.Style()
gauge = Gauge(root, padding=20)
gauge.pack()
ttk.Scale(root, from_=0, to=360, variable=gauge.arcvariable).pack(fill='x', padx=10, pady=10)
# update the textvariable with the degrees information when the arcvariable changes
gauge.arcvariable.trace_add('write', lambda *args, g=gauge: g.textvariable.set(f'{g.arcvariable.get()} deg'))
root.mainloop()
Issue Analytics
- State:
- Created 2 years ago
- Comments:23 (14 by maintainers)
Top Results From Across the Web
Getting started with Flutter Radial Gauge widget - Syncfusion
This section explains the steps required to add the Flutter Radial Gauge and its elements such as title, axis, range, pointer and annotation....
Read more >Niagara 4 Web Widget Gauge | Works Software
A radial gauge for Niagara 4. Includes main gauge value and 2 extra markers, e.g Peek Value and Last Month Peek. Set ord...
Read more >Add a Widget - DGLogik Wiki
You can add dynamic widgets such as callouts, charts, gauges, and lists to your location page or device template.
Read more >Linear Gauge Widget In Flutter - FlutterDevs
With this gauge, it is very easy to simulate a thermometer, progress bar, water tracker, etc. Demo Module : Implementation : Step 1:...
Read more >Getting Started with Flutter Radial Gauge Widget - YouTube
Get an overview of the Syncfusion Flutter Radial Gauge widget. This video explains how to add the Syncfusion Flutter Gauges package and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
yes. I’ve implemented the
step
method from the regular progressbar. Also, you can set the current and total values through the Meter.amountused and Meter.amounttotal properties. These properties are actually connected to the tkinter variables. If you want direct access to the variables, you can use Meter.amountusedvariable and Meter.amounttotalvariable.On Mon, May 3, 2021 at 7:47 AM Precise Simulation @.***> wrote:
I’ve completely reworked this widget to produce something that I think is extremely flexible. The one feature that I removed is the ability for it to auto-resize. I felt this was not strictly necessary, and added more overhead than I really wanted. However, this new widget has many customizable features and style possibilities.