Skip to main content

Rotatory dial-knob widgets for Tkinter.

Project description

TkDial

This is a library containing some circular rotatory dial-knob widgets for Tkinter. It can be used in place of normal sliders and scale.

PyPI Platform Downloads

Installation

pip install tkdial

Dial Widget

Usage

Simple Example:

import tkinter as tk
from tkdial import Dial

app = tk.Tk()

dial = Dial(app)
dial.grid(padx=10, pady=10)

app.mainloop()

Screenshot1

Example 2

import tkinter as tk
from tkdial import Dial

app = tk.Tk()

# some color combinations
color_combinations = [("yellow", "red"), ("white", "cyan"), ("red", "pink"), ("black", "green"),
                    ("white", "black"), ("blue", "blue"), ("green", "green"), ("white", "pink"),
                    ("red", "black"), ("green", "cyan"), ("cyan","black"), ("pink", "blue")]

for i in range (12):
    dial = Dial(master=app, color_gradient=color_combinations[i],
                unit_length=10, radius=40, needle_color=color_combinations[i][1])
    if i<6:
        dial.grid(row=1, padx=10, pady=10, column=i)
    else:
        dial.grid(row=2, padx=10, pady=10, column=11-i)

app.mainloop()

Screenshot2

Example 3

Implemented with CustomTkinter

import customtkinter
from tkdial import Dial

customtkinter.set_appearance_mode("Dark") 
              
app = customtkinter.CTk()
app.geometry("350x400")
                
app.grid_columnconfigure((0,1), weight=1)
app.grid_rowconfigure((0,1), weight=1)

frame_1 = customtkinter.CTkFrame(master=app)
frame_1.grid(padx=20, pady=20, sticky="nswe")

dial1 = Dial(master=frame_1, color_gradient=("green", "cyan"), bg="#2a2d2e",
             text_color="white", text="Current: ", unit_length=10, radius=50)
dial1.grid(padx=20, pady=20)

dial2 = Dial(master=frame_1, color_gradient=("yellow", "white"), bg="#2a2d2e",
             text_color="white", text="Position: ", unit_length=10, radius=50)
dial2.grid(padx=20, pady=20)

dial3 = Dial(master=frame_1, color_gradient=("white", "pink"), bg="#2a2d2e",
             text_color="white", text=" ", unit_length=10, radius=50)
dial3.grid(row=0, column=1, padx=20, pady=20)

dial4 = Dial(master=frame_1, color_gradient=("green", "green"), bg="#2a2d2e",
             text_color="white", text="", unit_width=15, radius=50)
dial4.grid(row=1, column=1, padx=20, pady=20)

app.mainloop()                  

Screenshot 3

Documentation

Options:

Parameters Description
master The master parameter is the parent widget
bg The default background color of the dial widget
width Define width of the widget manually (optional)
height Define height of the widget manually (optional)
x Determines the horizontal position of the dial in the canvas
y Determines the vertical position of the dial in the canvas
start The start point of the range from where the needle will rotate
end The end point of the range
radius Determines the distance of the unit lines between the center and the edge and also the length of the needle line
unit_length Specify the length of the lines
unit_width Specify the width of the lines
unit_color Specify the color of the unit lines
needle_color Specify the color of the needle line
color_gradient Specify which color gradient will be used for the units
text A string that will be displayed under the dial object
text_color Specify the color of the text that will be displayed under the dial object
text_font Specify the font of the text that will be displayed under the dial object
integer A boolean (True/False), displays only the integer value in text if True (default=False)
scroll A boolean (True/False), enables mouse scroll in dial (default=True)
scroll_steps Number of steps per scroll
state Specify the state of the needle
command Call a function whenever the needle is rotated

Methods:

Methods Description
.get() get the current value of the dial
.set() set the value of the dial
.configure() configure parameters of the dial

Scroll Knob

Usage

Simple Example

import tkinter
from tkdial import ScrollKnob
    
app = tkinter.Tk()

knob = ScrollKnob(app, start=0, end=100, steps=10)
knob.grid()
                
app.mainloop()      

Simple Program

Different Knob styles:

import customtkinter
from tkdial import ScrollKnob

app = customtkinter.CTk()
app.geometry("500x500")

knob1 = ScrollKnob(app, bg="#212325", radius=250, progress_color="#87ceeb", steps=10,
                 border_width=40, start_angle=90, inner_width=1, outer_width=1,
                 text_font="calibri 20", text_color="#87ceeb", bar_color="black")
knob1.grid(row=0, column=0)

knob2 = ScrollKnob(app, bg="#212325", radius=200, progress_color="#7eff00",
                 border_width=40, start_angle=90, inner_width=1, outer_width=0,
                 text_font="calibri 20", text_color="#7eff00", integer=True,
                 fg="#212325")
knob2.grid(row=1, column=0)

knob3 = ScrollKnob(app, bg="#212325", text=" ", radius=250, progress_color="white",
                   bar_color="#2937a6", border_width=30, start_angle=0, inner_width=5,
                   outer_width=0, text_font="calibri 20", steps=1, text_color="white", fg="#303ba1")
knob3.grid(row=0, column=1)

knob4 = ScrollKnob(app, bg=customtkinter.ThemeManager.theme["color"]["window_bg_color"][1],
                   text=" ", steps=10, radius=200, bar_color="#212325", progress_color="yellow",
                   outer_color="yellow", outer_length=10, border_width=30, start_angle=270,
                   inner_width=0, outer_width=5, text_font="calibri 20", text_color="white", fg="#212325")
knob4.grid(row=1, column=1)
                
app.mainloop()      

Complex example

Documentation

Options:

Parameters Description
master The master parameter is the parent widget
bg The default background color of the knob widget
width Define width of the widget manually (optional)
height Define height of the widget manually (optional)
start The start point of the range from where the bar will rotate
end The end point of the range
radius Define the radius of the knob
border_width Define the width of progress bar with respect to the outer and inner ring
start_angle Determines the angle from where to rotate
text A string that will be displayed on the knob
text_color Specify the color of the text that will be displayed on the knob
text_font Specify the font of the text that will be displayed on the knob
integer A boolean (True/False), displays only the integer value in text if True (default=False)
fg Define the color of the inner circle
progress_color Define the color of the progress bar
bar_color Define the color of the progress bar's background
inner_width Specify the width of the inner ring
inner_color Specify the color of the inner ring
outer_width Specify the width of the outer ring
outer_length Specify the distance between progress bar and outer ring
inner_color Specify the color of the outer ring
steps Number of steps per scroll
state Specify the state of the needle
command Call a function whenever the bar is moved

Methods:

Methods Description
.get() get the current value of the knob
.set() set the value of the knob
.configure() configure parameters of the knob

Conclusion

This library is focused to create some circular widgets that can be used with Tkinter easily. I hope it will be helpful for UI development in python.

Want to contribute? See this

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

tkdial-0.0.3.tar.gz (14.6 kB view hashes)

Uploaded Source

Built Distribution

tkdial-0.0.3-py3-none-any.whl (12.9 kB view hashes)

Uploaded Python 3

Supported by

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