here is my code:
from tkinter import*
import pyttsx3
import datetime
win=Tk()
win.configure(background="black")
win.geometry("500x700")
win.resizable(width=False,height=False)
#-----------------------------------------------------------------------------------------------------------------------------------------------
sys=pyttsx3.init()
voice_id="HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\TTS_MS_Cortana"
sys.setProperty("voice",voice_id)
def say(audio):
sys.say(audio)
sys.runAndWait()
return
def wishme():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
t1=Label(win,text="Good Morning, sir",font=("calibri",25),bg="black",fg="light green").grid(column=0,row=0,sticky=W)
t2=Label(win,text="What can I do for you today?",font=("calibri",18),bg="black",fg="light green").grid(column=0,row=2,sticky=W)
say("Good Morning ,sir.")
say("what can I do for you today?")
elif hour>=12 and hour<18:
t1=Label(win,text="Good Afternoon, sir",font=("calibri",25),bg="black",fg="light green").grid(column=0,row=0,sticky=W)
t2=Label(win,text="What can I do for you today?",font=("calibri",15),bg="black",fg="light green").grid(column=0,row=2,sticky=W)
say("Good Afternoon ,sir.")
say("what can I do for you today?")
elif hour>=18 and hour<21:
t1=Label(win,text="Good Evening, sir",font=("calibri",25),bg="black",fg="light green").grid(column=0,row=0,sticky=W)
t2=Label(win,text="What can I do for you today?",font=("calibri",18),bg="black",fg="light green").grid(column=0,row=2,sticky=W)
say("Good evening,sir.")
say("what can I do for you today?")
else:
t1=Label(win,text="Hello, sir",font=("calibri",25),bg="black",fg="light green").grid(column=0,row=0,sticky=W)
t2=Label(win,text="What can I do for you today?",font=("calibri",18),bg="black",fg="light green").grid(column=0,row=2,sticky=W)
say("Hello,sir.")
say("what can I do for you today?")
wishme()
win.mainloop()
what I am trying to make is to open my tkinter window first and then to wish me good morning or evening etc. But It is wishing me first then opening the tkinter window. Can anyone help me with it ?
First, set up all of your labels then have all of the calls to the
say()
function in thewishme()
function. tkinter'swin.after(100,wishme)
will runwishme()
after 100ms separately to the mainloop.