Created
May 3, 2014 18:58
-
-
Save Nagasaki45/40a763c3cebeb8aaadc2 to your computer and use it in GitHub Desktop.
Nuclear GUI for the Simcity project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
This program controls the state of the waterpump and | |
LED's of the nuclear power station. | |
If the pump stops working a countdown of 10 seconds starts | |
ticking and then does 2 things: | |
1) turning on red lights instead of blue lights in the | |
reactor's core. | |
2) cutting the power: writing outpin HIGH (on the arduino | |
of the power system this will set the power out. | |
if the pump is setted to work again, everything goes back to | |
normal state: | |
1) the blue lights are lighted. | |
2) the power outpin is set to LOW. | |
To control the state of the pump send in serial: | |
'h' - to turn the pump on | |
'l' - to turn the pump off | |
''' | |
import Tkinter as tk | |
# import serial | |
# Change the appropriate COM port number here! | |
# port_number = '13' | |
# port = 'COM' + port_number | |
# ser = serial.Serial(port, timeout=1, baudrate=9600) #com port number in windows is higher in one than the value, exa.:COM5=serial.Serial(4 | |
class NukeGuiBuilder(object): | |
def __init__(self): | |
win = tk.Tk() | |
win.wm_title('Nuclear Reactor Control') | |
self.photo1 = tk.PhotoImage(file='nuke1.gif') | |
self.photo2 = tk.PhotoImage(file='nuke2.gif') | |
turnon_button = tk.Button(win, | |
text='On', | |
command=self.turnon) | |
turnon_button.grid(row=0, column=0, padx=5, pady=0) | |
turnoff_button = tk.Button(win, | |
text='Off', | |
command=self.turnoff) | |
turnoff_button.grid(row=0, column=1, padx=5, pady=0) | |
self.nuke_image = tk.Label(win, image=self.photo1) | |
self.nuke_image.grid(row=0, column=3, padx=5, pady=5) | |
def turnon(self): | |
print('Pump working!') | |
# ser.write('h') | |
self.nuke_image.configure(image=self.photo1) | |
def turnoff(self): | |
print('Pump was turned off!') | |
# ser.write('l') | |
self.nuke_image.configure(image=self.photo2) | |
if __name__ == '__main__': | |
s = NukeGuiBuilder() | |
tk.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment