Showing Number of Text entered using Floodgauge style

Ttkbootstrap Floodgauge counter
Display the number of chars entered by the user and update the colour of the Meter by using bootstyle parameter.

Triggering function on adding or removal of chars inside Text widget

t1.bind("<KeyRelease>", my_upd)# Trigger on Key release event
More on Events

Ttkbootstrap Floodgauge widgets to show number of chars entered by user with colour zone bands #12


Function my_upd()

This function calculate the number of chars entered by the user inside the text widget. This value is displayed on the Label and our Meter m1 sets the amountused value to this number. Inside this function we will keep if elif condition checks to set the option bootstyle to different colors. There are 8 different colors are already avilable here is the list.

PRIMARY, SECONDARY, SUCCESS, INFO, WARNING, DANGER, LIGHT, DARK
def my_upd(value):
    my_str = t1.get("1.0", "end-1c")  # Read the string

    breaks = my_str.count("\n")  # Number of line breaks

    char_numbers = len(my_str) - breaks # Final number of chars

    l2.config(text=str(char_numbers))  # Display in Label

    fg.configure(value=char_numbers)  # Connect to Meter

    if fg.variable.get() < 25:
        fg.configure(bootstyle=INFO)
    elif fg.variable.get() < 50:
        fg.configure(bootstyle=SUCCESS)
    elif fg.variable.get() < 80:
        fg.configure(bootstyle=WARNING)
    else:
        fg.configure(bootstyle=DANGER)

    if char_numbers >= 100:  
        # Stop accepting chars after limit
        t1.delete("end-2c")  
        # Remove last char of text widget

import tkinter as tk
import ttkbootstrap as ttk
from ttkbootstrap.constants import *

# my_w = tk.Tk()
my_w = ttk.Window()
my_w.geometry("460x300")  # width x height of the window
my_w.title("www.plus2net.com")  # Adding a title

l1 = tk.Label(my_w, text="Your Data", width=10, font=20)  # added one Label
l1.grid(row=0, column=0, padx=3, pady=10, columnspan=2)

t1 = tk.Text(my_w, height=4, width=47, font=28)  # text box
t1.grid(row=1, column=0, padx=10, columnspan=2)

l2 = tk.Label(my_w, text=0, font=22)
l2.grid(row=2, column=0, padx=5, pady=5)

fg = ttk.Floodgauge(
    my_w,
    bootstyle=INFO,
    mask="Progress {}%",
    value=0,
    length=400,
)
fg.grid(row=2, column=1, padx=2, pady=20)


def my_upd(value):
    my_str = t1.get("1.0", "end-1c")  # read the string
    breaks = my_str.count("\n")  # Number of line breaks
    char_numbers = len(my_str) - breaks  # Final number of chars
    l2.config(text=str(char_numbers))  # display in Label
    fg.configure(value=char_numbers)  # connect to Meter

    if fg.variable.get() < 25:
        fg.configure(bootstyle=INFO)
    elif fg.variable.get() < 50:
        fg.configure(bootstyle=SUCCESS)
    elif fg.variable.get() < 80:
        fg.configure(bootstyle=WARNING)
    else:
        fg.configure(bootstyle=DANGER)

    if char_numbers >= 100:  # to stop accepting char after limit
        t1.delete("end-2c")  # remove last char of text widget


t1.bind("<KeyRelease>", my_upd)  # Trigger on Key release event
my_w.mainloop()  # Keep the window open
Ttkbootstrap Floodgauge start stop methods
Floodgauge ttkbootstrap
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer