title: How to flash tkinter label limited number of times, and only if conditions are met
body: <p>I have run the the nice example for a flashing tkinter label given in this answer: <a href="https://stackoverflow.com/questions/21419032/flashing-tkinter-labels/21439284#21439284">Flashing Tkinter Labels</a></p>
  
  <p>However, when I try to add some complexity to it, it fails.  </p>
  
  <p>First, I need it to only flash when certain conditions are met (It's an alarm, so, it should only flash in an alarm state, not in normal conditions).  </p>
  
  <p>Here is a basic version of what I want to do. </p>
  
  <pre><code>import Tkinter as tk
  import tkFont
  import epics
  
  global root
  
  class AlarmGUI:
      def __init__(self,parent):
          self.ending = False
  
          self.crhl = tk.Label(text='CFHT RH',bg='light blue')
          self.crhl.grid(row=1, column=2, 
                          padx=20, pady=20, sticky=tk.W)
          self.crhw = tk.Label(text='something',font=("Helvetica", 25,"bold"),bg='light blue')
          self.crhw.grid(row=2,column=0, sticky=tk.W)
  
          self.cfht()
  
      def flash(self):
          bg = self.crhw.cget('background')
          fg = self.crhw.cget('foreground')
          self.crhw.configure(background=fg,foreground=bg)
          self.crhw.after(1000,self.flash)  
  
      def cfht(self):
          #This reads in the value that is being tested
          crh = epics.caget('ws:wsHumid')    #Read in CFHT Relative Humidity
  
          #Here, I display the value 'crh'
          self.crhw.grid(row=2, column=2,sticky=tk.W+tk.E+tk.N+tk.S)
          self.crhw.configure(text=crh,fg='Red',bg='Gray')
  
          #Now I need to determine if the value crh is in an alarm state
          if (crh &gt; 85):  #If the value is over 85, I need the label to flash.
            self.crhw.flash()
  
          #Then this keeps checking the humidity value
          self.crhw.after(30000,cfht)
  
  def main():
      global root
  
      root = tk.Tk()
      gui = AlarmGUI(root)
      root.mainloop()
  
  if __name__ == '__main__':
      main() 
  </code></pre>
  
  <p>I have also tried to make the flash function only flash a certain number of times. When I say this (below), it does not flash.  It only prints to the screen 30 times, and then takes like 30 seconds before the gui appears on the screen, and does not flash:</p>
  
  <pre><code>def flash(self,count):
          bg = self.crhw.cget('background')
          fg = self.crhw.cget('foreground')
          self.crhw.configure(background=fg,foreground=bg)
          count +=1
          if (count &lt; 31):
               print count, bg, fg
               self.crhw.after(1000,self.flash(count)) 
  
  #And I call it with something like 
  self.flash(0) #to initialize the count
  </code></pre>