test1.py
from tkinter import *
from tkinter import messagebox
from test.regex import gendervalidation
app=Tk()
app.geometry("500x400")
app.title("Hancie e-Learning Studio")
def check():
txt = text.get()
genderResult=gendervalidation(txt)
if genderResult==True:
messagebox.showinfo("Info","The gender is valid")
else:
messagebox.showerror("Error","Invalid gender")
text=Entry(app,font=("Times New Roman",16))
text.pack()
btn=Button(app,text="Check Gender",font=("Times New Roman",16), command=check)
btn.pack()
app.mainloop()
regex.py
import re
# Function to validate Gender
def gendervalidation(gender):
# Regex to check valid GENDER
regex=re.compile("(?:m|M|male|Male|f|F|female|Female|FEMALE|MALE|Not prefer to say)$")
if re.fullmatch(regex, gender):
genderResult=True
else:
genderResult=False
return genderResult
Output