我正在创建一个虚拟代理&我正在使用Python 2.7库。下面是参考文献库的快照
import Tkinter as tk
from Tkinter import *
from PIL import Image
from PIL import ImageTk
from wx import Bottom
from wx.tools.img2py import img2py
#import PIL
import speech_recognition as sr
import pyttsx
import new
from time import gmtime, strftime
点击“开始对话”按钮,我会显示一个图像,然后是虚拟代理问候客户。下面是代码。
def Talk():
global FirstCall
global canvas1
global canvas2
global panel
canvas2.pack_forget()
panel.pack_forget()
image = Image.open("C:\Python27\Agent.gif")
photo = ImageTk.PhotoImage(image)
canvas1.image = photo # <--- keep reference of your image
canvas1.create_image(0,0,anchor='nw',image=photo)
canvas1.pack()
if FirstCall == 0:
CurTime = int(strftime("%H", gmtime()))
if CurTime < 12:
Say ("Hello, Good Morning")
elif CurTime > 12 and CurTime < 16:
Say ("Hello, Good Afternoon")
else:
Say ("Hello, Good Evening")
FirstCall = 1
以下是“谈话”按钮的使用方法: -
conversationbutton = Button(frame, text='Start Conversation', height=2,
width=40, bg="navy blue", fg="white",
font=("Arial", 10, "bold"), command=Talk)
conversationbutton.pack(side=BOTTOM, padx=7, pady=7)
问题:
根据代码序列,应首先显示图像。然后问候消息(早上好,下午好或晚上好。)
然而,在问候语后>>会显示图像。
预期:
首先显示图像,然后显示问候消息
请问您能说明可能出现的问题吗?