Facebook
From Posel, 3 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 138
  1. # Importing Libraries
  2.  
  3. import RPi.GPIO as GPIO
  4. import time
  5. from tkinter import *
  6. import tkinter.font
  7. from gpiozero import CPUTemperature
  8.  
  9. # Libraries Imported successfully
  10.  
  11. # Raspberry Pi 3 Pin Settings
  12.  
  13. LED = 12 # pin12
  14. GPIO.setwarnings(False)
  15. GPIO.setmode(GPIO.BOARD) # We are accessing GPIOs according to their physical location
  16. GPIO.setup(LED, GPIO.OUT) # We have set our LED pin mode to output
  17. GPIO.output(LED, GPIO.LOW) # When it will start then LED will be OFF
  18. cpu = CPUTemperature()
  19.  
  20. PwmValue = GPIO.PWM(LED, 50)
  21. PwmValue.start(0)
  22.  
  23. # Raspberry Pi 3 Pin Settings
  24.  
  25. # tkinter GUI basic settings
  26.  
  27. Gui = Tk()
  28. Gui.title("GUI in Raspberry Pi 3")
  29. Gui.config(background= "#0080FF")
  30. Gui.minsize(200,200)
  31. Font1 = tkinter.font.Font(family = 'Helvetica', size = 24, weight = 'bold')
  32.  
  33. # tkinter simple GUI created
  34.  
  35. def ledON():
  36.    GPIO.output(LED, GPIO.HIGH) # led on
  37.   #Text2 = Label(Gui,text=' ON ', font = Font1, bg = '#0080FF', fg='green', padx = 0)
  38.    #Text2.grid(row=0,column=1)
  39.  
  40. def ledOFF():
  41.     GPIO.output(LED, GPIO.LOW) # led off
  42.     #Text2 = Label(Gui,text='OFF', font = Font1, bg = '#0080FF', fg='red', padx = 0)
  43.    #Text2.grid(row=0,column=1)
  44.  
  45. def ChangePWM(self):
  46.     PwmValue.ChangeDutyCycle(Scale1.get())
  47.    
  48. def ChangeFREQ(self):
  49.     PwmValue.ChangeFrequency(Scale2.get())
  50.  
  51. #Text1 = Label(Gui,text='LED Status:', font = Font1, fg='#FFFFFF', bg = '#0080FF', padx = 50, pady = 50)
  52. #Text1.grid(row=0,column=0)
  53.  
  54. #Text2 = Label(Gui,text='OFF', font = Font1, fg='#FFFFFF', bg = '#0080FF', padx = 0)
  55. #Text2.grid(row=0,column=1)
  56.  
  57. #Button1 = Button(Gui, text=' LED ON', font = Font1, command = ledON, bg='bisque2', height = 1, width = 10)
  58. #Button1.grid(row=1,column=0)
  59.  
  60. #Button2 = Button(Gui, text=' LED OFF', font = Font1, command = ledOFF, bg='bisque2', height = 1, width = 10)
  61. #Button2.grid(row=1,column=1)
  62.  
  63. Text1 = Label(Gui,text=cpu.temperature, font = Font1, fg='#FFFFFF', bg = '#0080FF', padx = 50, pady = 50)
  64. Text1.grid(row=0,column=0)
  65.    
  66. Scale1 = Scale(Gui, from_=0, to=100, orient = HORIZONTAL, resolution = 1, command = ChangePWM)
  67. Scale1.grid(row=1,column=0)
  68.  
  69. Scale2 = Scale(Gui, from_=1, to=50, orient = HORIZONTAL, resolution = 0.5, command = ChangeFREQ)
  70. Scale2.grid(row=1,column=2)
  71.  
  72. #Text3 = Label(Gui,text='www.TheEngineeringProjects.com', font = Font1, bg = '#0080FF', fg='#FFFFFF', padx = 50, pady = 50)
  73. #Text3.grid(row=2,columnspan=2)
  74.  
  75. Gui.mainloop()
  76.