I want to display the time when I am displaying my message. I did it but the time would not be updated. It will remain as the time when I started the mainloop. Below I attached my code. I will appreciate any form of help I could get as I am a noob trying to learn Python. Thanks.
from tkinter import *
import time
time3 = time.strftime('%H:%M:%S')
def tick():
global time1
time2 = time.strftime('%H:%M:%S')
clock.config(text=time2)
clock.after(200, tick)
root = Tk()
root.title("Test GUI")
time1 = ' '
def newfile():
message = (time3 + ':' + "Creating new file..... \n")
text.insert(0.0, message)
def openfile():
message = (time3 + ':' + "Opening existing file..... \n")
text.insert(0.0, message)
def starttest():
message = (time3 + ':' + "Start testing \n")
text.insert(0.0, message)
def stoptest():
message = (time3 + ':' + "Stop testing \n")
text.insert(0.0, message)
topFrame = Frame(root)
topFrame.pack(side = TOP)
bottomFrame = Frame(root)
bottomFrame.pack(side = BOTTOM)
clock = Label(root, font=('times', 10, 'bold'), bd = 1, relief = SUNKEN, anchor = E)
but1 = Button(topFrame, text = "START", command = starttest)
but2 = Button(topFrame, text = "STOP", command = stoptest)
text = Text(topFrame, width = 35, height = 5, wrap = WORD)
clock.pack(side = BOTTOM, fill = X)
but1.grid(row = 3, column = 3)
but2.grid(row = 3, column = 4)
text.grid(row = 1, column = 0, columnspan =2, sticky = W)
menu = Menu(topFrame)
root.config(menu = menu)
subMenu = Menu(menu)
menu.add_cascade(label = "File", menu = subMenu)
subMenu.add_command(label = "New File", command = newfile)
subMenu.add_command(label = "Open File", command = openfile)
tick()
root.mainloop()