Advertisement
Guest User

Untitled

a guest
Nov 30th, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import sys
  2. if 3 == sys.version_info[0]: ## 3.X is default if dual system
  3. import tkinter as tk ## Python 3.x
  4. else:
  5. import Tkinter as tk ## Python 2.x
  6.  
  7. win=tk.Tk()
  8. win.title("Q")
  9. def toggle():
  10. if b1.config('text')[-1] == 'AMBIENT':
  11. b1.config(text='OFF')
  12. GPIO.setup(24, GPIO.OUT)
  13. GPIO.output(24, GPIO.LOW)
  14. else:
  15. b1.config(text='AMBIENT')
  16. GPIO.output(24, GPIO.HIGH)
  17. if b2.config('text')[-1] == 'CEILING':
  18. b2.config(text='OFF')
  19. GPIO.setup(18, GPIO.OUT)
  20. GPIO.output(18, GPIO.LOW)
  21. else:
  22. b2.config(text='CEILING')
  23. GPIO.output(18, GPIO.HIGH)
  24.  
  25. b1 = tk.Button(win, text="AMBIENT", command=toggle)
  26. b2 = tk.Button(win, text="CEILING", command=toggle)
  27.  
  28. ## 3 & 4 not used in this example
  29. ##b3 = Button(win, text="LASER", command=toggle)
  30. ##b4 = Button(win, text="RADIO", command=toggle)
  31.  
  32. b1.pack(pady=2)
  33. b2.pack(pady=2)
  34. ##b3.pack(pady=2)
  35. ##b4.pack(pady=2)
  36.  
  37. win.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement