Aug-09-2017, 01:16 PM
(This post was last modified: Aug-09-2017, 03:32 PM by sparkz_alot.)
Thanks for the reply. What I have accomplished is that I can change the parameters of the buttons when each is depressed but what I need to do is to have that button change color depending on the data returned to Python from an Arduino anlog input bit of data. In other words, I depress the GUI button with the Pytho/Tkinter GUI screen and my mouse and that sends a command to the Arduino which switches a relay. I would like the button to change colors and / or text only when the Arduino sends back data to Python that the relay has actually changed position. I have a contact from the relay that sends a fixed voltage to an Arduino analog input and I can see that value in the data stam but I just CAN NOT figure out how to use that bit of data to modify the button color. Help please.
This works it just doesn't really reflect the relays' switching status. The label between the buttons changes color and text when each button is depressed. I need those labels to do their thing only when the Arduino data says they have changed state.
import serial
import Tkinter
arduinoData = serial.Serial('com10', 9600)
def changeCol0s():
butt0["bg"]="red"
butt0["fg"]="black"
butt0["text"]="AIRCARD#30\nSIM STATUS\nutility SIM"
return
def changeCol0u():
butt0["bg"]="green"
butt0["fg"]="black"
butt0["text"]="AIRCARD#30\nSIM STATUS\nnormal SIM"
def changeCol1s():
butt1["bg"]="red"
butt1["fg"]="black"
butt1["text"]="AIRCARD#31\nSIM STATUS\nutility SIM"
return
def changeCol1u():
butt1["bg"]="green"
butt1["fg"]="black"
butt1["text"]="AIRCARD#31\nSIM STATUS\nnormal SIM"
def changeCol2s():
butt2["bg"]="red"
butt2["fg"]="black"
butt2["text"]="AIRCARD#32\nSIM STATUS\nutility SIM"
return
def changeCol2u():
butt2["bg"]="green"
butt2["fg"]="black"
butt2["text"]="AIRCARD#32\nSIM STATUS\nnormal SIM"
def changeCol3s():
butt3["bg"]="red"
butt3["fg"]="black"
butt3["text"]="AIRCARD#33\nSIM STATUS\nutility SIM"
return
def changeCol3u():
butt3["bg"]="green"
butt3["fg"]="black"
butt3["text"]="AIRCARD#33\nSIM STATUS\nnormal SIM"
def changeCol4s():
butt4["bg"]="red"
butt4["fg"]="black"
butt4["text"]="AIRCARD#34\nSIM STATUS\nutility SIM"
return
def changeCol4u():
butt4["bg"]="green"
butt4["fg"]="black"
butt4["text"]="AIRCARD#34\nSIM STATUS\nnormal SIM"
def changeCol5s():
butt5["bg"]="red"
butt5["fg"]="black"
butt5["text"]="AIRCARD#35\nSIM STATUS\nutility SIM"
return
def changeCol5u():
butt5["bg"]="green"
butt5["fg"]="black"
butt5["text"]="AIRCARD#35\nSIM STATUS\nnormal SIM"
def changeCol6s():
butt6["bg"]="red"
butt6["fg"]="black"
butt6["text"]="AIRCARD#36\nSIM STATUS\nutility SIM"
return
def changeCol6u():
butt6["bg"]="green"
butt6["fg"]="black"
butt6["text"]="AIRCARD#36\nSIM STATUS\nnormal SIM"
def led1_on():
arduinoData.write('2')
print "Aircard 30 is now using the Utility SIM"
def led1_off():
arduinoData.write('3')
print "Aircard 30 is now using the Normal SIM"
def led2_on():
arduinoData.write('4')
print "Aircard 31 is now using the Utility SIM"
def led2_off():
arduinoData.write('5')
print "Aircard 31 is now using the Normal SIM"
def led3_on():
arduinoData.write('6')
print "Aircard 32 is now using the Utility SIM"
def led3_off():
arduinoData.write('7')
print "Aircard 32 is now using the Normal SIM"
def led4_on():
arduinoData.write('8')
print "Aircard 33 is now using the Utility SIM"
def led4_off():
arduinoData.write('9')
print "Aircard 33 is now using the Normal SIM"
def led5_on():
arduinoData.write('A')
print "Aircard 34 is now using the Utility SIM"
def led5_off():
arduinoData.write('B')
print "Aircard 34 is now using the Normal SIM"
def led6_on():
arduinoData.write('C')
print "Aircard 35 is now using the Utility SIM"
def led6_off():
arduinoData.write('D')
print "Aircard 35 is now using the Normal SIM"
def led7_on():
arduinoData.write('E')
print "Aircard 36 is now using the Utility SIM"
def led7_off():
arduinoData.write('F')
print "Aircard 36 is now using the Normal SIM"
import sys
from Tkinter import*
from time import sleep
root = Tk()
frame = Frame(root)
frame.pack()
root.title("SIM SWAP SYSTEM")
num1=StringVar()
topframe = Frame(root)
topframe.pack(side = TOP)
txtDisplay = Button(frame, bg="green", fg="black", text="Medical Justice Services, Inc. / Dental Justice / eMerit\nSIM SWAP SYSTEM\nAIRCARDS 30-36")
txtDisplay.pack(side = TOP)
frame0 = Frame(root)
frame0.pack(side=TOP)
button0s = Button(frame0, padx=16, bd=8, text="AIRCARD#30\npress this button\nto swap to utility SIM", command = lambda: [changeCol0s(),led1_on()])
button0s.pack(side=LEFT)
butt0 = Label(frame0, text="AIRCARD#30\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt0.pack(side=LEFT)
button0u = Button(frame0, padx=16, bd=8, text="AIRCARD#30\npress this button\nto swap to normal SIM", command = lambda:[changeCol0u(),led1_off()])
button0u.pack(side=LEFT)
frame1 = Frame(root)
frame1.pack(side = TOP)
button1s = Button(frame1, padx=16, bd=8, text="AIRCARD#31\npress this button\nto swap to utility SIM", command = lambda: [changeCol1s(),led2_on()])
button1s.pack(side = LEFT)
butt1 = Label(frame1, text="AIRCARD#31\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt1.pack(side=LEFT)
button1u = Button(frame1, padx=16, bd=8, text="AIRCARD#31\npress this button\nto swap to normal SIM", command = lambda:[changeCol1u(),led2_off()])
button1u.pack(side = LEFT)
frame2 = Frame(root)
frame2.pack(side = TOP)
button2s = Button(frame2, padx=16, bd=8, text="AIRCARD#32\npress this button\nto swap to utility SIM", command = lambda: [changeCol2s(),led3_on()])
button2s.pack(side = LEFT)
butt2 = Label(frame2, text="AIRCARD#32\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt2.pack(side=LEFT)
button2u = Button(frame2, padx=16, bd=8, text="AIRCARD#32\npress this button\nto swap to normal SIM", command = lambda:[changeCol2u(),led3_off()])
button2u.pack(side = LEFT)
frame3 = Frame(root)
frame3.pack(side = TOP)
button3s = Button(frame3, padx=16, bd=8, text="AIRCARD#33\npress this button\nto swap to utility SIM", command = lambda: [changeCol3s(),led4_on()])
button3s.pack(side = LEFT)
butt3 = Label(frame3, text="AIRCARD#33\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt3.pack(side=LEFT)
button3u = Button(frame3, padx=16, bd=8, text="AIRCARD#33\npress this button\nto swap to normal SIM", command = lambda:[changeCol3u(),led4_off()])
button3u.pack(side = LEFT)
frame4 = Frame(root)
frame4.pack(side = TOP)
button4s = Button(frame4, padx=16, bd=8, text="AIRCARD#34\npress this button\nto swap to utility SIM", command = lambda: [changeCol4s(),led5_on()])
button4s.pack(side = LEFT)
butt4 = Label(frame4, text="AIRCARD#34\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt4.pack(side=LEFT)
button4u = Button(frame4, padx=16, bd=8, text="AIRCARD#34\npress this button\nto swap to normal SIM", command = lambda:[changeCol4u(),led5_off()])
button4u.pack(side = LEFT)
frame5 = Frame(root)
frame5.pack(side = TOP)
button5s = Button(frame5, padx=16, bd=8, text="AIRCARD#35\npress this button\nto swap to utility SIM", command = lambda: [changeCol5s(),led6_on()])
button5s.pack(side = LEFT)
butt5 = Label(frame5, text="AIRCARD#35\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt5.pack(side=LEFT)
button5u = Button(frame5, padx=16, bd=8, text="AIRCARD#35\npress this button\nto swap to normal SIM", command = lambda:[changeCol5u(),led6_off()])
button5u.pack(side = LEFT)
frame6 = Frame(root)
frame6.pack(side = TOP)
button6s = Button(frame6, padx=16, bd=8, text="AIRCARD#36\npress this button\nto swap to utility SIM", command = lambda: [changeCol6s(),led7_on()])
button6s.pack(side = LEFT)
butt6 = Label(frame6, text="AIRCARD#36\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt6.pack(side=LEFT)
button6u = Button(frame6, padx=16, bd=8, text="AIRCARD#36\npress this button\nto swap to normal SIM", command = lambda:[changeCol6u(),led7_off()])
button6u.pack(side = LEFT)
root.mainloop()
This works it just doesn't really reflect the relays' switching status. The label between the buttons changes color and text when each button is depressed. I need those labels to do their thing only when the Arduino data says they have changed state.
import serial
import Tkinter
arduinoData = serial.Serial('com10', 9600)
def changeCol0s():
butt0["bg"]="red"
butt0["fg"]="black"
butt0["text"]="AIRCARD#30\nSIM STATUS\nutility SIM"
return
def changeCol0u():
butt0["bg"]="green"
butt0["fg"]="black"
butt0["text"]="AIRCARD#30\nSIM STATUS\nnormal SIM"
def changeCol1s():
butt1["bg"]="red"
butt1["fg"]="black"
butt1["text"]="AIRCARD#31\nSIM STATUS\nutility SIM"
return
def changeCol1u():
butt1["bg"]="green"
butt1["fg"]="black"
butt1["text"]="AIRCARD#31\nSIM STATUS\nnormal SIM"
def changeCol2s():
butt2["bg"]="red"
butt2["fg"]="black"
butt2["text"]="AIRCARD#32\nSIM STATUS\nutility SIM"
return
def changeCol2u():
butt2["bg"]="green"
butt2["fg"]="black"
butt2["text"]="AIRCARD#32\nSIM STATUS\nnormal SIM"
def changeCol3s():
butt3["bg"]="red"
butt3["fg"]="black"
butt3["text"]="AIRCARD#33\nSIM STATUS\nutility SIM"
return
def changeCol3u():
butt3["bg"]="green"
butt3["fg"]="black"
butt3["text"]="AIRCARD#33\nSIM STATUS\nnormal SIM"
def changeCol4s():
butt4["bg"]="red"
butt4["fg"]="black"
butt4["text"]="AIRCARD#34\nSIM STATUS\nutility SIM"
return
def changeCol4u():
butt4["bg"]="green"
butt4["fg"]="black"
butt4["text"]="AIRCARD#34\nSIM STATUS\nnormal SIM"
def changeCol5s():
butt5["bg"]="red"
butt5["fg"]="black"
butt5["text"]="AIRCARD#35\nSIM STATUS\nutility SIM"
return
def changeCol5u():
butt5["bg"]="green"
butt5["fg"]="black"
butt5["text"]="AIRCARD#35\nSIM STATUS\nnormal SIM"
def changeCol6s():
butt6["bg"]="red"
butt6["fg"]="black"
butt6["text"]="AIRCARD#36\nSIM STATUS\nutility SIM"
return
def changeCol6u():
butt6["bg"]="green"
butt6["fg"]="black"
butt6["text"]="AIRCARD#36\nSIM STATUS\nnormal SIM"
def led1_on():
arduinoData.write('2')
print "Aircard 30 is now using the Utility SIM"
def led1_off():
arduinoData.write('3')
print "Aircard 30 is now using the Normal SIM"
def led2_on():
arduinoData.write('4')
print "Aircard 31 is now using the Utility SIM"
def led2_off():
arduinoData.write('5')
print "Aircard 31 is now using the Normal SIM"
def led3_on():
arduinoData.write('6')
print "Aircard 32 is now using the Utility SIM"
def led3_off():
arduinoData.write('7')
print "Aircard 32 is now using the Normal SIM"
def led4_on():
arduinoData.write('8')
print "Aircard 33 is now using the Utility SIM"
def led4_off():
arduinoData.write('9')
print "Aircard 33 is now using the Normal SIM"
def led5_on():
arduinoData.write('A')
print "Aircard 34 is now using the Utility SIM"
def led5_off():
arduinoData.write('B')
print "Aircard 34 is now using the Normal SIM"
def led6_on():
arduinoData.write('C')
print "Aircard 35 is now using the Utility SIM"
def led6_off():
arduinoData.write('D')
print "Aircard 35 is now using the Normal SIM"
def led7_on():
arduinoData.write('E')
print "Aircard 36 is now using the Utility SIM"
def led7_off():
arduinoData.write('F')
print "Aircard 36 is now using the Normal SIM"
import sys
from Tkinter import*
from time import sleep
root = Tk()
frame = Frame(root)
frame.pack()
root.title("SIM SWAP SYSTEM")
num1=StringVar()
topframe = Frame(root)
topframe.pack(side = TOP)
txtDisplay = Button(frame, bg="green", fg="black", text="Medical Justice Services, Inc. / Dental Justice / eMerit\nSIM SWAP SYSTEM\nAIRCARDS 30-36")
txtDisplay.pack(side = TOP)
frame0 = Frame(root)
frame0.pack(side=TOP)
button0s = Button(frame0, padx=16, bd=8, text="AIRCARD#30\npress this button\nto swap to utility SIM", command = lambda: [changeCol0s(),led1_on()])
button0s.pack(side=LEFT)
butt0 = Label(frame0, text="AIRCARD#30\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt0.pack(side=LEFT)
button0u = Button(frame0, padx=16, bd=8, text="AIRCARD#30\npress this button\nto swap to normal SIM", command = lambda:[changeCol0u(),led1_off()])
button0u.pack(side=LEFT)
frame1 = Frame(root)
frame1.pack(side = TOP)
button1s = Button(frame1, padx=16, bd=8, text="AIRCARD#31\npress this button\nto swap to utility SIM", command = lambda: [changeCol1s(),led2_on()])
button1s.pack(side = LEFT)
butt1 = Label(frame1, text="AIRCARD#31\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt1.pack(side=LEFT)
button1u = Button(frame1, padx=16, bd=8, text="AIRCARD#31\npress this button\nto swap to normal SIM", command = lambda:[changeCol1u(),led2_off()])
button1u.pack(side = LEFT)
frame2 = Frame(root)
frame2.pack(side = TOP)
button2s = Button(frame2, padx=16, bd=8, text="AIRCARD#32\npress this button\nto swap to utility SIM", command = lambda: [changeCol2s(),led3_on()])
button2s.pack(side = LEFT)
butt2 = Label(frame2, text="AIRCARD#32\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt2.pack(side=LEFT)
button2u = Button(frame2, padx=16, bd=8, text="AIRCARD#32\npress this button\nto swap to normal SIM", command = lambda:[changeCol2u(),led3_off()])
button2u.pack(side = LEFT)
frame3 = Frame(root)
frame3.pack(side = TOP)
button3s = Button(frame3, padx=16, bd=8, text="AIRCARD#33\npress this button\nto swap to utility SIM", command = lambda: [changeCol3s(),led4_on()])
button3s.pack(side = LEFT)
butt3 = Label(frame3, text="AIRCARD#33\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt3.pack(side=LEFT)
button3u = Button(frame3, padx=16, bd=8, text="AIRCARD#33\npress this button\nto swap to normal SIM", command = lambda:[changeCol3u(),led4_off()])
button3u.pack(side = LEFT)
frame4 = Frame(root)
frame4.pack(side = TOP)
button4s = Button(frame4, padx=16, bd=8, text="AIRCARD#34\npress this button\nto swap to utility SIM", command = lambda: [changeCol4s(),led5_on()])
button4s.pack(side = LEFT)
butt4 = Label(frame4, text="AIRCARD#34\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt4.pack(side=LEFT)
button4u = Button(frame4, padx=16, bd=8, text="AIRCARD#34\npress this button\nto swap to normal SIM", command = lambda:[changeCol4u(),led5_off()])
button4u.pack(side = LEFT)
frame5 = Frame(root)
frame5.pack(side = TOP)
button5s = Button(frame5, padx=16, bd=8, text="AIRCARD#35\npress this button\nto swap to utility SIM", command = lambda: [changeCol5s(),led6_on()])
button5s.pack(side = LEFT)
butt5 = Label(frame5, text="AIRCARD#35\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt5.pack(side=LEFT)
button5u = Button(frame5, padx=16, bd=8, text="AIRCARD#35\npress this button\nto swap to normal SIM", command = lambda:[changeCol5u(),led6_off()])
button5u.pack(side = LEFT)
frame6 = Frame(root)
frame6.pack(side = TOP)
button6s = Button(frame6, padx=16, bd=8, text="AIRCARD#36\npress this button\nto swap to utility SIM", command = lambda: [changeCol6s(),led7_on()])
button6s.pack(side = LEFT)
butt6 = Label(frame6, text="AIRCARD#36\nSIM STATUS\n normal SIM.", bg="green", font="Arial 8 bold", width=15, height=3, anchor="n")
butt6.pack(side=LEFT)
button6u = Button(frame6, padx=16, bd=8, text="AIRCARD#36\npress this button\nto swap to normal SIM", command = lambda:[changeCol6u(),led7_off()])
button6u.pack(side = LEFT)
root.mainloop()