title: Using MQTT to update Tkinter GUI?
body: <p>I have a virtual light bulb (Tkinter GUI), I have two separate images for if the bulb is on or off. I am trying to figure out how I can use MQTT (paho mqtt) to turn this virtual bulb on or off. I am able to publish and subscirbe to topics, and I can use the received message ("On" or "Off") to determine which image to display, I just cannot figure out how to update this when a new message is received. </p>
  
  <p>This is where I am creating the Tkinter GUI</p>
  
  <pre><code>#!/usr/bin/python3
  
  from tkinter import *
  from PIL import ImageTk, Image
  import os
  import sys
  
  root = Tk()
  root.geometry("768x1024")
  
  if sys.argv[1]:
      if sys.argv[1] == "On":
          img = ImageTk.PhotoImage(Image.open("light-on.jpg"))
      else:
          img = ImageTk.PhotoImage(Image.open("light-off.jpg"))
  
  panel = Label(root, image = img)
  panel.pack(side = "bottom", fill = "both", expand = "yes")
  root.mainloop()
  </code></pre>
  
  <p>And this is where I am subscribing to the topic and retrieving messages.</p>
  
  <pre><code>#! /usr/bin/python3
  import paho.mqtt.client as mqtt #import the client1
  import time
  import subprocess
  import tkinter as tk
  import random
  
  def on_message(client, userdata, message):
      print("message received " ,str(message.payload.decode("utf-8")))
      print("message topic=",message.topic)
      print("message qos=",message.qos)
      print("message retain flag=",message.retain)
      subprocess.call(['./pythongui.py',message.payload.decode()])
  
  broker_address="test.mosquitto.org"
  
  print("creating new instance")
  client = mqtt.Client() #create new instance
  client.on_message=on_message #attach function to callback
  
  print("connecting to broker")
  client.connect(broker_address) #connect to broker
  
  print("Subscribing to topic","house/bulbs/bulb1")
  client.subscribe("house/bulbs/bulb1")
  
  client.loop_forever()
  </code></pre>
  
  <p>I am aware that I probably shouldn't be creating a subprocess and this is probably completely wrong but I cannot figure out how to do this. Any tips would be appreciated.</p>