title: Tkinter - function that force graph and label to update
body: <p>I'm trying to create a window which contains a graph (created from points), and label depends on string variable who I can also change with a function that update them</p>
  <p>The problem I faced is creating a function that force the graph and the label to update and show the new variables.
  this is what I tried</p>
  <blockquote>
  <p>class gui:</p>
  <p>def <strong>init</strong>(self):
  self.root = None
  self.txt = None</p>
  <p>def vp_start_gui(self):
  self.<strong>init</strong>()
  self.root = tk.Tk()
  INSERT YOUR WHOLE CODE HERE&quot;&quot;&quot;
  data_cpu = {'Time': update_time(),
  'CPU utilization': update_cpu()
  }
  df_cpu = DataFrame(data_cpu, columns=['Time', 'CPU utilization'])</p>
  <p>figure_cpu = plt.Figure(figsize=(5, 4), dpi=100)
  ax_cpu = figure_cpu.add_subplot(111)
  line_cpu = FigureCanvasTkAgg(figure_cpu, self.root)
  line_cpu.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH)
  df_cpu = df_cpu[['Time', 'CPU utilization']].groupby('Time').sum()
  df_cpu.plot(kind='line', legend=True, ax=ax_cpu, color='b', marker='o', fontsize=10)
  ax_cpu.set_title('CPU utilization over time')</p>
  <p>lbl = tk.Button(self.root, text=self.txt, bd='2')
  lbl.pack(side='top')</p>
  <p>btn = tk.Button(self.root, text='REFRESH', bd='2',
  command=self.refresh)</p>
  <p>btn.pack(side='top')
  CREATE A BUTTON AND ITS command = refresh() which is defined at the bottom&quot;&quot;&quot;
  self.root.mainloop()</p>
  <p>def changeLabel(self, text):
  self.txt = text</p>
  <p>def refresh(self):
  self.root.destroy()
  self.vp_start_gui()</p>
  <p>def main(self):
  self.vp_start_gui()
  #self.changeLabel(&quot;second&quot;)</p>
  <p>a = gui()
  a.main()</p>
  </blockquote>