title: Make Tkinter run a command without clicking or pressing a button
body: <p>I am making a simple <code>tkinter</code> popup where you can type a message.
  In the textbox itself, I inserted the text &quot;Type your message here&quot; with a grey colour and when clicked, the inserted text is deleted so the user can type in their own message. In addition, the colour of the text typed by the user is set to black.</p>
  <p>However, when I was testing I realised that this will only happen if they click the textbox with a mouse button.  My question is, is there a way for <code>tkinter</code> to automatically run a command when a condition is changed? For example, if the textbox is empty, the font colour should be set to black.<br />
  I tried putting if-statements in the <code>tk.mainloop</code>, but sadly that didn't work.</p>
  <p>Any ideas?</p>
  <p>this is my (hopefully) simplified version of the code:</p>
  <pre><code>from tkinter import *
  
  def changecolor(event):
      if textbox.get(&quot;1.0&quot;, &quot;end-1c&quot;) == &quot;Type your message here&quot;:
          textbox.delete(&quot;1.0&quot;, &quot;end&quot;)
          textbox.config(fg='black')
  
  root = Tk()
  
  canvas = Canvas(root, height=400, width=600)
  canvas.pack()
  
  textbox = Text(canvas, font=40, fg=&quot;grey&quot;)
  textbox.insert(1.0, &quot;Type your message here&quot;)
  textbox.bind(&quot;&lt;Button-1&gt;&quot;, changecolor)
  textbox.pack()
  
  root.mainloop()
  </code></pre>
  <p>~finally found out how to format code here.</p>