
t1.bind("<KeyRelease>", my_upd)# Trigger on Key release event
More on Events
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 Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.