Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #AI CAR GAUGE By Justin S Hagerty
- #Date 12/11/2016
- #Not Yet Opperational Just Test Files
- from tkinter import *
- import time
- window_w = 800
- window_h = 350
- numberofbuttons = 7
- gaugeaccuracy = 31
- buttonnames = ["Display Settings", "Gauge Reset", "Instrument Panel", "Test","Test","Test","Gauges"]
- yes=" "
- def creategauge(inputa):
- for i in range(0,gaugeaccuracy):
- carstart.inputa.append(yes)
- carstart2.inputa.append(yes)
- class carstart1():
- gas = 30
- rpm = 30
- speed = 30
- oiltemp = 30
- coolanttemp = 30
- class carstart2():
- gas = 1
- rpm = 1
- speed = 1
- oiltemp = 1
- coolanttemp = 1
- class car():
- gas = 1
- rpm = 1
- speed = 1
- oiltemp = 1
- coolanttemp = 1
- class gauge():
- gas = []
- gastext = []
- speed = []
- oiltemp = []
- coolanttemp = []
- rpm = []
- led = []
- def createdisplay():
- global tk, canvas, light
- tk = Tk()
- canvas = Canvas(tk, width=window_w, height=window_h, background="black")
- canvas.pack()
- createbuttonbar()
- tk.mainloop()
- def createbuttonbar():
- creategauge()
- buttonlist = []
- for i in range(0,numberofbuttons):
- buttonlist.append(yes)
- buttonlist[0] = Button(tk, text=buttonnames[0], command=displaysettings, bg="blue")
- buttonlist[1] = Button(tk, text=buttonnames[1], command=test, bg="blue")
- buttonlist[2] = Button(tk, text=buttonnames[2], command=test, bg="blue")
- buttonlist[3] = Button(tk, text=buttonnames[3], command=test, bg="blue")
- buttonlist[4] = Button(tk, text=buttonnames[4], command=test, bg="blue")
- buttonlist[5] = Button(tk, text=buttonnames[5], command=test, bg="blue")
- buttonlist[6] = Button(tk, text=buttonnames[6], command=showgauge, bg="blue")
- for i in range(0,numberofbuttons):
- width = 100
- height = 52
- x = 0
- y = 50 * i
- buttonlist[i].place(x=x,y=y,height=height,width=width)
- def displaysettings():
- resetgaugs()
- print("display settings")
- tk.update()
- def showgauge():
- fillcolor="red"
- for i in range(0,gaugeaccuracy):
- canvas.itemconfig(gauge.gas[i], fill=fillcolor)
- canvas.itemconfig(gauge.speed[i], fill=fillcolor)
- canvas.itemconfig(gauge.rpm[i], fill=fillcolor)
- canvas.itemconfig(gauge.oiltemp[i], fill=fillcolor)
- canvas.itemconfig(gauge.coolanttemp[i], fill=fillcolor)
- fillcolor="white"
- for i in range(0, len(gauge.gastext)):
- canvas.itemconfig(gauge.gastext[i], fill=fillcolor)
- tk.update()
- carstart()
- def creategauge():
- global tk, canvas
- gaugefill = ""
- textfill = ""
- for i in range(0,gaugeaccuracy):
- x = 100
- y = window_h - 30 - (i * 10)
- x1= 150
- y1= window_h - 30 - (i * 10 - 5)
- b = i*.53
- b = round(b, 2)
- if i % 10:
- x1 = 130
- else:
- gauge.gastext.append(canvas.create_text(x+70,y, fill=textfill, text=b))
- gauge.gas.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
- x = 200
- y = window_h - 30 - (i * 10)
- x1= 250
- y1= window_h - 30 - (i * 10 - 5)
- b = 5 * i
- if i % 2:
- x1 = 230
- else:
- gauge.gastext.append(canvas.create_text(x+65,y, fill=textfill, text=b))
- gauge.speed.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
- x = 300
- y = window_h - 30 - (i * 10)
- x1= 350
- y1= window_h - 30 - (i * 10 - 5)
- b = 250 * i
- if i % 2:
- x1 = 330
- else:
- gauge.gastext.append(canvas.create_text(x+70,y, fill=textfill, text=b))
- gauge.rpm.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
- x = 400
- y = window_h - 30 - (i * 10)
- x1= 450
- y1= window_h - 30 - (i * 10 - 5)
- b = 25 * i
- if i % 3:
- x1 = 430
- else:
- gauge.gastext.append(canvas.create_text(x+70,y, fill=textfill, text=b))
- gauge.coolanttemp.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
- x = 500
- y = window_h - 30 - (i * 10)
- x1= 550
- y1= window_h - 30 - (i * 10 - 5)
- b = 25 * i
- if i % 3:
- x1 = 530
- else:
- gauge.gastext.append(canvas.create_text(x+70,y, fill=textfill, text=b))
- gauge.oiltemp.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
- x = 600
- y = window_h - 30 - (i * 10)
- x1= 610
- y1= window_h - 30 - (i * 10 - 5)
- if i % 5:
- x1 = 600
- else:
- gauge.gastext.append(canvas.create_text(x+25,y, fill=textfill, text="test"))
- gauge.led.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
- y = window_h - 10
- x = 115
- gauge.gastext.append(canvas.create_text(x,y, fill=textfill, text="Gas"))
- gauge.gastext.append(canvas.create_text(x+100,y, fill=textfill, text="Speed"))
- gauge.gastext.append(canvas.create_text(x+200,y, fill=textfill, text="Rpm"))
- gauge.gastext.append(canvas.create_text(x+320,y, fill=textfill, text="Coolant Temp"))
- gauge.gastext.append(canvas.create_text(x+400,y, fill=textfill, text="Oil Temp"))
- tk.update()
- def carstart():
- for i in range(0, gaugeaccuracy):
- time.sleep(.05)
- if i < carstart1.gas :
- canvas.itemconfig(gauge.gas[i], fill="white")
- if i < carstart1.speed :
- canvas.itemconfig(gauge.speed[i], fill="white")
- if i < carstart1.rpm :
- canvas.itemconfig(gauge.rpm[i], fill="white")
- if i < carstart1.oiltemp :
- canvas.itemconfig(gauge.oiltemp[i], fill="white")
- if i < carstart1.coolanttemp :
- canvas.itemconfig(gauge.coolanttemp[i], fill="white")
- tk.update()
- resetgauge()
- time.sleep(.15)
- i = 0
- for i in range(0, gaugeaccuracy):
- time.sleep(.05)
- if i < carstart2.gas :
- canvas.itemconfig(gauge.gas[i], fill="white")
- if i < carstart2.speed :
- canvas.itemconfig(gauge.speed[i], fill="white")
- if i < carstart2.rpm :
- canvas.itemconfig(gauge.rpm[i], fill="white")
- if i < carstart2.oiltemp :
- canvas.itemconfig(gauge.oiltemp[i], fill="white")
- if i < carstart2.coolanttemp :
- canvas.itemconfig(gauge.coolanttemp[i], fill="white")
- tk.update()
- def resetgauge():
- for i in range(0, gaugeaccuracy):
- time.sleep(.05)
- if i < carstart1.gas :
- canvas.itemconfig(gauge.gas[i], fill="red")
- if i < carstart1.speed :
- canvas.itemconfig(gauge.speed[i], fill="red")
- if i < carstart1.rpm :
- canvas.itemconfig(gauge.rpm[i], fill="red")
- if i < carstart1.oiltemp :
- canvas.itemconfig(gauge.oiltemp[i], fill="red")
- if i < carstart1.coolanttemp :
- canvas.itemconfig(gauge.coolanttemp[i], fill="red")
- tk.update()
- def update():
- for i in range(0, gaugeaccuracy):
- time.sleep(.012)
- if i < car.gas :
- canvas.itemconfig(gauge.gas[i], fill="white")
- if i < car.speed :
- canvas.itemconfig(gauge.speed[i], fill="white")
- if i < car.rpm :
- canvas.itemconfig(gauge.rpm[i], fill="white")
- if i < car.oiltemp :
- canvas.itemconfig(gauge.oiltemp[i], fill="white")
- if i < car.coolanttemp :
- canvas.itemconfig(gauge.coolanttemp[i], fill="white")
- tk.update()
- def test():
- print("test")
- def terminate():
- global tk
- tk.destroy()
- def main():
- createdisplay()
- main()
Advertisement
Add Comment
Please, Sign In to add comment