OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Closing tkinter window after a function is done executing

  • Thread starter Thread starter Jaheen
  • Start date Start date
J

Jaheen

Guest
I'm trying to have a tkinter window open and have another function running in the background using the threading module, and I'd like to have the window close once the function is done executing. What I'm having trouble with, though, is figuring out if there is a way to use the after method to eventually close the window since I know it's time-dependent, and there isn't really a good way to estimate when the function would be done running. Would you guys happen to know of a way I could have the window open while the function is running and have it close once it's done? Here's some sample code I wrote:

Code:
 win=Tk()
 thread_1=threading.Thread(target=function, args=(args,))
 thread_1.start()
 win.title("Collecting Results for {}".format(var))
 interface=mainWindow(win)
 interface.my_canvas.create_text(900/2, 600/3.50, text="Please wait as we are collecting results for {}".format(var), font=("Arial, 20"), fill="white")
 win.after(*this is where I could use help*,win.destroy)
 win.mainloop()
<p>I'm trying to have a <code>tkinter</code> window open and have another function running in the background using the <code>threading</code> module, and I'd like to have the window close once the function is done executing. What I'm having trouble with, though, is figuring out if there is a way to use the <code>after</code> method to eventually close the window since I know it's time-dependent, and there isn't really a good way to estimate when the function would be done running. Would you guys happen to know of a way I could have the window open while the function is running and have it close once it's done?
Here's some sample code I wrote:</p>
<pre><code> win=Tk()
thread_1=threading.Thread(target=function, args=(args,))
thread_1.start()
win.title("Collecting Results for {}".format(var))
interface=mainWindow(win)
interface.my_canvas.create_text(900/2, 600/3.50, text="Please wait as we are collecting results for {}".format(var), font=("Arial, 20"), fill="white")
win.after(*this is where I could use help*,win.destroy)
win.mainloop()
</code></pre>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top