0

I currently have this code:

import easygui, random, time, math, sys
from Tkinter import *

root=Tk()
root.geometry('800x800')
c=Canvas(root, width=800, height=800)
c.pack()
done=False
x=1
while not done:
    #do something
    root.update()
    x=x+1
    if x>=5:
        c.destroy()
    else:
        done=False

y=easygui.buttonbox("The program should continue",
                    choices=['Yes','No'])

I would like the program to continue after the 'if x>5:' branch, onto the easygui portion of my code. I looked this question up, and found c.destroy. Unfortunately, it ends my code entirely, so the easygui button box doesn't even appear. Does anybody know how to delete the Tkinter canvas, and go on with the program. Would using ttk instead of easygui solve my problem? Or is there a simple fix in continuing my code with the same method I'm using?

Kat
  • 7
  • 5
  • As you `pack` your canvas, you should be able to `pack_forget` it to remove it from view, and not end your program. – SneakyTurtle Jul 13 '17 at 18:30
  • You will never get to the easygui code because you never exit the while(), i.e. done is always False. –  Jul 13 '17 at 18:35

1 Answers1

0

it ends my code entirely, so the easygui button box doesn't even appear.

No it doesn't. It just removes the window, and then your code is still stuck in the loop forever. In addition to c.destroy(), you need to stop the while loop by adding a break:

if x>=5:
    c.destroy()
    break
Novel
  • 13,406
  • 2
  • 25
  • 41