Python Forum

Full Version: [split] Closing a window but not the whole program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i got almost the same problem
import time
from tkinter import messagebox

count = 0
print("Your Antivirus will scan your Computer  ")
# messagebox.showinfo("", "Your Antivirus will scan your Computer  ")
time.sleep(2)

print('scanning Computer.....')
time.sleep(3)

while count <= 100:
    print("Antivirus scanning Computer....", count, "%")
    count  += 1
    time.sleep(0.01)
messagebox.showinfo("", "Scaning again from Terminal  ")
# frame.destroy()
i need help with the script parts that are a comment
i cant close the tkinter window without it stoping the hole script
pls help
im kinda a noob in that.
thanks
greeting drache (german for dragon)
here's an example of a main window with multiple toplevel windows the pink window is tied with the main and will not close until the main closes the red and blue are independent:
from tkinter import Frame,Canvas,Button,Tk,Toplevel,Label


class MainWindowExample(Frame):
    def __init__(self, parent= None):
        self.parent= parent
        Frame.__init__(self, self.parent)
        self.pack(expand='yes', fill='both')
        self.canvas= Canvas(self)
        self.canvas.config(width=500,height=300, bg='gray80')
        self.canvas.pack(expand='yes', fill='both')
        self.make_components()
    def make_components(self):
        self.label_1= Label(self.canvas, text='button One')
        self.label_1.place(x=10,y=10)
        self.button_1= Button(self.canvas, text='popup2', command=self.popup_2)
        self.button_1.place(x=100,y=10)
        self.myToplevel= Toplevel(width=200,height=250,bg='red')#seperate window
        self.myToplevel.title('example')
        self.myTopLevel_2= Toplevel(width=200,height=250,bg='pink') #closes w/main
        self.myTopLevel_2.protocol('WM_DELETE_WINDOW', lambda:None)
    def popup_2(self):
        self.toplevel= Toplevel(width=200,height=250,bg='blue')
        self.toplevel.title('example2')
if __name__ == '__main__':
    root= Tk()
    MainWindowExample(root)
    root.mainloop()
This can also be done other ways....