Tkinter更改后图片消失

时间:2018-06-27 08:30:11

标签: python-3.x tkinter

我有这个问题:我用Python3和Tkinter创建了该程序,它们显示了一个地方(如高山或大海)的图片,并且程序说出了图片中显示的地方。问题是当图片改变时,它只出现一会儿,正好是程序说出什么位置的时间,而消失并仅保留写有代表图片的标签。 这是代码:

from tkinter import *
from PIL import Image,ImageTk
import pyttsx3

root = Tk()
root.title("Try change image")
root.geometry("1000x600") 
root.resizable(height=FALSE,width=FALSE)

Leftframe = Frame(root)
Leftframe.pack(side = LEFT)
Rightframe = Frame(root)
Rightframe.pack(side=RIGHT)

engine = pyttsx3.init()
voices = engine.getProperty('voices')
rate = engine.getProperty('rate')
engine.setProperty('rate', rate -20)
for voice in voices:
    engine.setProperty('voice',voice.id)

def start():
    global back_label,label
    back = ImageTk.PhotoImage(file=directory mountain picture)
    back_label = Label(Leftframe,image = back)
    back_label.pack()

    label=Label(Rightframe,text="Mountain")
    label.pack()
    root.update()
    engine.say("Mountain")
    engine.runAndWait()





def change():
    back_label.destroy()
    label.destroy()
    back = ImageTk.PhotoImage(file=directory sea picture)
    back_label1 = Label(Leftframe,image = back)
    back_label1.pack()

    label1 = Label(Rightframe,text="Sea")
    label1.pack()
    root.update()
    engine.say("Sea")
    engine.runAndWait()


start()
change()
root.mainloop()

希望您能理解我想做什么,我们将不胜感激

0 个答案:

没有答案