1

I wrote a restart program but it does not work

retry = Button(text="play again", width=11, bg="black", fg="grey99", command=restart)
retry.pack()

And the restart function is below

def restart():
    global window
    window.destroy()  # destroy and create a new one
    window = Tk()
    global screenheight
    global screenwidth
    screenwidth = window.winfo_screenwidth()
    screenheight = window.winfo_screenheight()
    window.geometry("{0}x{1}+0+0".format(window.winfo_screenwidth(), window.winfo_screenheight()))
    window.title("Predict future")
    canvas = Canvas(window, width=screenwidth, height=screenwidth, bg="ghost white")
    canvas.place(x=500, y=300)
    taiji = PhotoImage(file="taiji.gif")
    taijitu = Label(image=taiji)
    intro = Button(window, image=taijitu, command=New)
    intro.place(x=-120, y=-60)

So it just destroys the old one and creates a new window, but the photo image doesn't show up (I guess it had been garbage collected).

Munim Munna
  • 17,178
  • 6
  • 29
  • 58
Mike Chen
  • 11
  • 2
  • People edit your question to make it more readable for people to answer. When you edit your question keep the formatting, do not rollback to the messy state ([revision 4](https://stackoverflow.com/posts/50935328/revisions)). – Munim Munna Jul 07 '18 at 06:50
  • Possible duplicate of [\_tkinter.TclError: image "..." doesn't exist](https://stackoverflow.com/questions/45668895/tkinter-tclerror-image-doesnt-exist) – eyllanesc Jul 07 '18 at 07:40

0 Answers0