Closing tkinter on button press

Moderator: Kathy_9

Post Reply
blendmo
Posts: 12
Joined: Tue Dec 18, 2018 6:38 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
Corel programs: PSP 2019 Ultimate

Closing tkinter on button press

Post by blendmo »

New to tkinter. Trying to destroy() the window on a button event. Something like this:

Code: Select all

class TestWindow(Frame):
    def __init__(self):
        # set the title of the window
        Frame.__init__(self)
        self.pack(expand=YES, fill=BOTH)
        self.master.title('Test Custom Input')

        # the button that do stuff and close window
        Button(
            text="Click Me!",
            width=25,
            height=5,
            command=self.conclude
            ).pack()
            
    def conclude(self):
            self.destroy()
Utilizing the standard foreign window:

Code: Select all

def Do(Environment):
    # just show the dialog
    Wnd = TestWindow()
    App.Do( Environment, 'StartForeignWindow', { 'WindowHandle': int(Wnd.winfo_id()) } )
    Wnd.mainloop()
    App.Do( Environment, 'StartForeignWindow', { 'WindowHandle': 0 } )
Instead of the window closing and returning control to the Do function, it just puts the window behind PSP. However if I click the [X] button to close, it does what I expect. What am I missing?
LeviFiction
Advisor
Posts: 5985
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8, 9, X, XI, X2, X8,X9, 2018, 2019
Location: USA

Re: Closing tkinter on button press

Post by LeviFiction »

Destroy the master.

Code: Select all

    def conclude(self):
            self.master.destroy()
blendmo
Posts: 12
Joined: Tue Dec 18, 2018 6:38 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
Corel programs: PSP 2019 Ultimate

Re: Closing tkinter on button press

Post by blendmo »

As always, thank you for sharing your expertise.
Post Reply