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
- BUTTON_SIZE = 20
- NUM_BUTTON = 20
- MARGIN = 5
- WINDOW_H = MARGIN+((BUTTON_SIZE+MARGIN)*NUM_BUTTON)
- WINDOW_W = (2*MARGIN)+(BUTTON_SIZE)*40
- #Set colours
- # R G B
- BLACK = '#000000'
- BRIGHTRED = '#ff0000'
- RED = '#9b0000'
- LIGHTOFFON=[RED,BRIGHTRED]
- OFF = 0
- ON = 1
- colourBackground = BLACK
- colourButton = RED
- #Light Status
- gasarray=[ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON]
- speedratio = 180/140
- changerate = .25
- datarate = .05
- yes = True
- on = "yes"
- class startcar():
- gas = 0
- coolant_temp = 0
- speed = 0
- rpm = 0
- speed = (140 - speed) * speedratio
- class car:
- gas = 2
- coolant_temp = 0
- if yes == True:
- speed = 10
- else:
- speed = 50
- speed = (140 - speed) * speedratio
- rpm = 0
- class caradjust():
- gas = 19
- coolant_temp = 0
- speed = 0
- rpm = 0
- def createDisplay():
- global tk, canvas, light, speedgauge
- # create the tk window - within which
- # everything else will be built.
- tk = Tk()
- #Add a canvas area ready for drawing on
- canvas = Canvas(tk, width=WINDOW_W, height=WINDOW_H, background=BLACK)
- canvas.pack()
- #Add some "lights" to the canvas
- light = []
- for i in range(0,NUM_BUTTON):
- x = MARGIN+((MARGIN+BUTTON_SIZE)*i)
- light.append(canvas.create_rectangle(MARGIN,x,
- BUTTON_SIZE+MARGIN,x+BUTTON_SIZE,fill=RED))
- if i == 0:
- canvas.create_text(MARGIN+BUTTON_SIZE*3,x*2,fill="white",text="FULL")
- if i == NUM_BUTTON-1:
- canvas.create_text(MARGIN+BUTTON_SIZE*3,x+(x/40),fill="white",text="EMPTY")
- btn = Button(tk, text="Exit", command=terminate)
- btn.pack()
- btn2 = Button(tk, text="Yesss", command=gasgaugeupdate)
- btn2.pack()
- # Create keyboard bindings
- # Start the tk main-loop (this updates the tk display)
- tk.mainloop()
- #def updateloop():
- def gasgaugeupdate():
- B = 5
- A = 0
- while B < len(gasarray):
- B = B + 1
- A = 21 - B
- time.sleep(changerate)
- gasarray[A-1] = gastoggle(gasarray[A-1])
- canvas.itemconfig(light[A-1], fill=LIGHTOFFON[gasarray[A-1]])
- tk.update()
- def gastoggle(value):
- value == ON
- return value
- def toggle(value):
- if value == ON:
- value = OFF
- else:
- value = ON
- return value
- def terminate():
- global tk
- tk.destroy()
- def main():
- createDisplay()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment