Quote:it will run for 60 secs and after 60sec it will disappear
How are you incrementing the progress bar? Nothing will happen until the subprocess returns so you will have to use Tkinter's after method to update the progress bar if you want it to update while the subprocess is still running. A simple example using a countdown timer to simulate whatever the subprocess does, and a different progress bar because that is what is already in this program.
try:
import Tkinter as tk
except:
import tkinter as tk
class ProgressBar():
def __init__(self, root):
self.root=root
self.root.geometry("75x50+1200+100")
tk.Button(self.root, text="Quit", bg="red", command=self.root.destroy).pack()
self.ctr=60 ## 60 seconds
self.start_progress_bar()
self.start_countdown()
def start_progress_bar(self):
""" create a simple progress bar widget on a canvas
"""
self.top=tk.Toplevel(self.root, takefocus=True)
self.top.title("Progress Bar")
self.top.geometry("+1200+300")
self.canvas = tk.Canvas(self.top, width=261, height=60, background='lightgray')
self.canvas.pack()
self.rc1 = self.canvas.create_rectangle(24, 20, 32, 50, outline='white', \
fill='blue')
self.start_x=20
self.end_x=235
self.this_x=self.start_x
self.one_25th = (self.end_x-self.start_x)/25.0
rc2 = self.canvas.create_rectangle(self.start_x, 20, self.end_x, 50,
outline='blue', fill='lightblue')
self.rc1 = self.canvas.create_rectangle(self.start_x, 20, self.start_x+7, 50,
outline='white', fill='blue')
self.update_scale()
def start_countdown(self):
""" a separate process in a separate GUI
"""
self.top2=tk.Toplevel(self.root, bg="lightyellow")
self.top2.geometry("100x25+1200+200")
self.label_ctr = tk.IntVar()
self.label_ctr.set(self.ctr)
tk.Label(self.top2, textvariable=self.label_ctr, width=10,
font=("Verdans", 15)).pack()
self.update()
def update(self):
if self.ctr > 0:
self.label_ctr.set(self.ctr)
self.ctr -= 1
self.root.after(1000, self.update) ## one second
else:
## sleep for one second to allow any remaining after() to execute
## can also use self.root.after_cancel(id)
self.root.after(1000, self.root.destroy)
def update_scale(self):
self.canvas.move(self.rc1, self.one_25th, 0)
self.canvas.update()
self.this_x += self.one_25th
## reverse direction at either end
if (self.this_x >= self.end_x-12) or self.this_x <= self.start_x+7:
self.one_25th *= -1
## only call after() while the countdown is running (self.ctr > 0)
## to avoid a dangling after() when the program terminates
if self.ctr > 0:
self.canvas.after(200, self.update_scale)
root = tk.Tk()
PB=ProgressBar(root)
root.mainloop()