Header Ads

Responsive Ads Here

Status Bar


STATUS BAR

import tkinter as tk

import math

window = tk.Tk()

status_bar = tk.Label(window)

status_bar.pack(side= tk.BOTTOM, fill="x")
status_bar.configure(bg="blue", foreground="white")
text= tk.Text(window)
text.pack(fill="both", expand=True)
text.configure(bg="Green", foreground="yellow")


def changed(event=None):
   #edit_modified is a function which helps to check whether there is a change in text
    if text.edit_modified():

        # If you want to consider space in character as well you can remove
        .replace(" ", "")
        chars = len(text.get(1.0, "end-1c").replace(" ", ""))
        words = len(text.get(1.0, "end-1c").split())
        line = text.index(tk.INSERT).split(".")[0]
        cursor = text.index(tk.INSERT).split(".")[1]
        status_bar.config(text=f"Characters: {chars}, Words: {words}, Line: {line}, Cursor: {cursor}")

    text.edit_modified(False)
text.bind("<<Modified>>", changed)

window.mainloop()



Powered by Blogger.