这是我的代码:
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()
我要做的是先打开我的 tkinter 窗口,然后祝我早安或晚上等。但它是先祝我然后打开 tkinter 窗口。任何人都可以帮我吗?