python - How do I update this Text Box's text in Tkinter? -
so making stopwatch in python tkinter, have loop updating time working, have loop clears text box, , updates text box new number.
although doesnt work, reason doesnt clear it, keeps adding numbers box.
here code have used, if able have @ me appriciate lot :)
import time tkinter import * root = tk() root.title("stopwatch") #textbox screen screen = text(root, height = 1, width = 20, bd=10) screen.grid(row=0, column=0) #active variable global stopwatch_active stopwatch_active = false stop_time = 0 stop_minutes = 0 #command starting stopwatch def start_com(): stop_btn.config(state=normal) stopwatch_active = true start_btn.config(state=disabled) global stop_time stop_time += 1 screen.insert(end, stop_time) root.after(1000, start_com) #button starting stopwatch start_btn = button(root, text = "start", width = 10, bd = 5, command = start_com) start_btn.grid(row=1, column=0, sticky=w) #button stopping stopwatch stop_btn = button(root, text = "stop", width = 10, bd = 5) stop_btn.grid(row=1, column=0, sticky=e) stop_btn.config(state=disabled)
add:
screen.delete("1.0", end)
before do:
screen.insert(end, stop_time)
this clear text text box. effbot has more information if interested. produce similar to:
Comments
Post a Comment