Advertisement
Guest User

asdf

a guest
Oct 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from gpiozero import LED
  2. from gpiozero.pins.pigpio import PiGPIOFactory
  3. from time import sleep
  4. import tkinter as tk
  5. from tkinter import *
  6. ip = PiGPIOFactory(host="192.168.43.150")
  7. led = LED(4, pin_factory=ip)
  8.  
  9. class Application(tk.Frame):
  10.     def __init__(self, master=None):
  11.         super().__init__(master)
  12.         self.master = master
  13.         self.pack()
  14.         self.create_widgets()
  15.  
  16.     def create_widgets(self):
  17.         self.btn_on = tk.Button(self)
  18.         self.btn_on["text"] = "Led an"
  19.         self.btn_on["command"] = self.led_on
  20.         self.btn_on.pack(side="top")
  21.         self.btn_off = tk.Button(self)
  22.         self.btn_off["text"] = "Led aus"
  23.         self.btn_off["command"] = self.led_off
  24.         self.btn_off.pack(side="top")
  25.  
  26.     def led_on(self):
  27.         led.on()
  28.         print("on")
  29.         sleep(5)
  30.     def led_off(self):
  31.         led.off()
  32.         print("off")
  33.         sleep(5)
  34.  
  35. root = tk.Tk()
  36. app = Application(master=root)
  37. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement