0

I have this problem: I created this program with Python3 and Tkinter, that show the picture of a place (like mountain or sea) and the program speak what is the place shown in the picture. The problem is when the picture change, it only appears for a few moments, just the time the program say what place is, and the disappear and remain only the label where it is written what represent the picture. This is the code:

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()

I hope you understand what I want to do, every help will be appreciated

Dante
  • 15
  • 4
  • Possible duplicate of [Why does Tkinter image not show up if created in a function?](https://stackoverflow.com/questions/16424091/why-does-tkinter-image-not-show-up-if-created-in-a-function) – fhdrsdg Jun 27 '18 at 09:22
  • Ok, thank you. I checked the other topic and the related link, now it works. Do I have to delete this question? (because is a duplicate of the other one) – Dante Jun 27 '18 at 09:32
  • If the question I linked solves your problem, I believe you can accept it to be a duplicate, which closes the question. It's not necessary to delete the question, as explained in [this meta post](https://meta.stackoverflow.com/a/265737/3714930). – fhdrsdg Jun 27 '18 at 09:36

0 Answers0