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
#1
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)
Reply
#2
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....
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 346 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [PyQt] PyQt5 window closing when trying to display a graph bianca 4 1,621 Aug-12-2023, 03:25 PM
Last Post: bianca
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 728 Aug-06-2023, 01:54 AM
Last Post: deanhystad
  [Tkinter] [split] [split] How to make a window stay on top knoxvilles_joker 10 6,035 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 13,417 Jan-18-2021, 10:21 PM
Last Post: Serafim
  [PyQt] Received RunTimeError after script concludes, closing Dialog Window (clicking x-out) skipper0802 0 2,527 Oct-09-2020, 09:23 PM
Last Post: skipper0802
  Closing window on button click not working kenwatts275 4 3,673 May-03-2020, 01:59 PM
Last Post: deanhystad
  Running cli program within a wx window? t4keheart 2 2,729 Jan-23-2020, 04:50 PM
Last Post: buran
  tkinter window and turtle window error 1885 3 6,625 Nov-02-2019, 12:18 PM
Last Post: 1885
  [Tkinter] Closing a window but not the whole program Wiggy1 2 4,944 Jan-11-2019, 12:51 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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