Python Forum
Tkinter/Label/Arduino/ if Else condition - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Tkinter/Label/Arduino/ if Else condition (/thread-5765.html)



Tkinter/Label/Arduino/ if Else condition - emrebt39 - Oct-20-2017

from Tkinter import *
root = Tk()
def connectToArduino():

    arduino = serial.Serial(arduinoPort,   serialTransferRate)
    arduino.timeout = None
    time.sleep(2)
    arduino.write("S\n")

    lab=Label(root, text="Connected")
    lab.grid()
    return arduino, lab
    lab.config(text="Disconnected")
arduino = connectToArduino()
arduino.pack()
root.mainloop()
When Arduino Connected serial to PC,Label has Connected MSG.When discomnected,MSG is disconnected.
How could i make if Else condition about Connected or Disconnected messages in Label?


RE: Tkinter/Label/Arduino/ if Else condition - Larz60+ - Oct-20-2017

Send a request (ping) to the arduino to which it will respond if connected
If you get a response, just make sure it's not a timeout, and you have your
trigger for messages.

You can get some other idea's here: http://www.instructables.com/id/Interface-Python-and-Arduino-with-pySerial/