Python Forum
[split] Closing a window but not the whole program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Closing a window but not the whole program
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  ")

print('scanning Computer.....')

while count <= 100:
    print("Antivirus scanning Computer....", count, "%")
    count  += 1
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.
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')
    def make_components(self):
        self.label_1= Label(self.canvas, text='button One'),y=10)
        self.button_1= Button(self.canvas, text='popup2', command=self.popup_2),y=10)
        self.myToplevel= Toplevel(width=200,height=250,bg='red')#seperate window
        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')
if __name__ == '__main__':
    root= Tk()
This can also be done other ways....

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] [split] [split] How to make a window stay on top knoxvilles_joker 10 2,533 May-22-2021, 03:54 AM
Last Post: knoxvilles_joker
Question closing a "nested" window with a button in PySimpleGUI and repeating this process Robby_PY 9 3,295 Jan-18-2021, 10:21 PM
Last Post: Serafim
  [PyQt] Received RunTimeError after script concludes, closing Dialog Window (clicking x-out) skipper0802 0 949 Oct-09-2020, 09:23 PM
Last Post: skipper0802
  Closing window on button click not working kenwatts275 4 1,075 May-03-2020, 01:59 PM
Last Post: deanhystad
  Running cli program within a wx window? t4keheart 2 1,637 Jan-23-2020, 04:50 PM
Last Post: buran
  tkinter window and turtle window error 1885 3 3,202 Nov-02-2019, 12:18 PM
Last Post: 1885
  [Tkinter] Closing a window but not the whole program Wiggy1 2 2,578 Jan-11-2019, 12:51 AM
Last Post: Larz60+
  How to stop a tkinter function, without closing the window? keakins 5 9,280 Jun-29-2017, 11:53 AM
Last Post: keakins
  Closing Modal Window in QT nieselfriem 0 3,413 Apr-19-2017, 03:32 PM
Last Post: nieselfriem
  update a variable in parent window after closing its toplevel window gray 5 5,654 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020