0
votes

I have a GUI containing multiple pages and I define all my functions under the parent class (APP). I am using the threading.Timer to update the progress of a current function. This function is also defined under the parent class (let's call it update_time()).

I have a progressbar on page three of the GUI that I would like to update every time the threading Timer updates. How would I access the progressbar on page 3 of the GUI from the function update_time() in order to update the progressbar with every threading timer update?

def update_time(self):
    timer = threading.Timer(self.update_interval, self.update_time)
    timer.start()

    self.current_count += 1
    current_percentage = self.current_count / self.total_count
    current_percentage = current_percentage if current_percentage <= 1 else 1

    # This is the progress bar that would reside on PageThree
    PageThree.progress['value'] = round(current_percentage, 3) * 100
    PageThree.style.configure('text.Horizontal.TProgressbar', text='{:.1%}'.format(current_percentage))

The PageThree.progress obviously does not work, but I am looking for a similar idea of calling the progress bar within the class PageThree and updating it to the current percentage.

1
You need to pass PageThree into update_time() each time it is called, or have it passed into the __init__() of this class, so that self.PageThree.progress... will work.quamrana
If you want a coherent answer, you're going to need to add more code to your question that gives us an overall idea of the design of your app.martineau
Please create a minimal reproducible example that replicates the problem you're having, but with the fewest lines of code possible.Bryan Oakley

1 Answers

0
votes

I ended up setting the Progressbar variable as a global DoubleVar() and updated that variable in the function call. (This is not functional code, just an example to give the general idea)

class MainPage(tk.Tk)

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
      
    def update_time(self, a_num):
        progress = a_num
        PageThree.update_progress(self, progress)


class PageThree(tk.Frame)

      def update_progress(self, val):
          treatment_progress_var.set(val)

      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)

          global progress_var
          progress_var = DoubleVar()


           ttk.Progressbar(self, orient=HORIZONTAL, 
           textvariable=treatment_progress_txt, 
           mode='determinate', variable=treatment_progress_var)

This will allow the Progressbar to be updated every time the update_time() is called