I have code in a method that creates a progress bar:
def progress_bar(self, message = None, icon_path = None, icon_name = None, size = 0, file_location = None, interval = 100):
#size: in bytes of download
#file_location: location of the download
#interval: frequency, in ms, of how often to poll the file for progress
self.find_icon(icon_path, icon_name)
self.text_label = tk.Label(text = message)
self.set_colors(self.text_label)
self.set_colors(self.image_label)
self.image_label.grid(row = 1, column = 1, sticky = 'NSEW')
self.text_label.grid(row = 1, column = 2, sticky = 'NSEW')
self.progress = ttk.Progressbar(self, orient="horizontal", length=(self.xp/3), mode="determinate")
self.progress.grid(row = 1, column = 3, sticky = 'NSEW')
self.progress["value"] = 0
self.progress["maximum"] = size
self.auto_resize(1, 3)
self.progress.start(interval)
self.after(1, self.check_for_completion(file_location))
self.mainloop()
def check_for_completion(self, file_location):
#while (self.progress["value"] < self.progress["maximum"]):
self.progress["value"] = os.stat(file_location).st_size
print self.progress["value"]
if (self.progress["value"] >= self.progress["maximum"]):
self.text_label = tk.Label(text = message + ": Completed")
#force a repaint and wait for the user to see it
self.text_label.grid(row = 1, column = 2)
time.sleep(30)
self.choice(True)
self._delete_window
and by way of sanity testing, I have a _ _ main _ _ method in the the same script and what I want to do is create a temp file, launch the progress bar and then start putting chars into the temp file. Unfortunately, I cannot find a way to launch the progress bar in a non blocking way.
I tried playing with python Multiprocessing like this:
p = Process(target = frame4.progress_bar, kwargs = kwarrgh)
p.start()
p.join()
and got a very angry ;) message saying
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
NOTE: The important part of this exercise is to launch the Tkinter window in the background from the main, not the other way around. I've found a bunch of SO questions on the latter, but not the former.
The answer is not required to be threadsafe, in case there is a multithreading rather than multiprocessing approach that works.
Aucun commentaire:
Enregistrer un commentaire