test1.py
from tkinter import *
from tkinter import messagebox
from test.regex import timevalidation
app=Tk()
app.geometry("500x400")
app.title("Hancie e-Learning Studio")
def check():
txt = text.get()
timeResult=timevalidation(txt)
if timeResult==True:
messagebox.showinfo("Info","The time is valid")
else:
messagebox.showerror("Error","Invalid time")
text=Entry(app,font=("Times New Roman",16))
text.pack()
btn=Button(app,text="Check Time",font=("Times New Roman",16), command=check)
btn.pack()
app.mainloop()
regex.py
import re
# Function to validate Gender
def timevalidation(time):
# Regex to check valid time
regex=re.compile("(0[1-9]|1[0-2]):([0-5][0-9]) ((a|p)m|(A|P)M)")
if re.fullmatch(regex, time):
timeResult=True
else:
timeResult=False
return timeResult
Output