from Tkinter import * import serial class MainWindow(Frame): """ Create a homepage and a page for each region that will appear if that region is touched """ def __init__(self, *args, **kwargs): Frame.__init__(self, *args, **kwargs) self.msg = Label(self, text='Welcome to the beta Interactive Brain.\n\ Touch the brain to learn more about it.') self.msg.pack(padx=20,pady=10) # self.button = Button(self, text="Frontal Lobe", # command=self.frontal_lobe) # self.button.pack(padx=10) self.button_close = Button(self, text="Quit", command='exit') self.button_close.pack(padx=10,pady=10) def region_page(self, region_number): titles = {1: 'Frontal Lobe', 2: 'Cortex'} texts = {1: "This is the frontal lobe.\n\ The region that is asssociated with reasoning, planning\n\ parts of speech, movement, emotions, and problem solving.", 2: 'blah blah'} root = Toplevel(self) root.title(titles[region_number]) # [NOT NEEDED?] setting names as variables to handle calling 5 regions # region_name = StringVar() # Label(root, textvariable=region_name).pack(pady=10) # region_name.set('Frontal Lobe') Label(root, text=titles[region_number]).pack(pady=10) # separator is showing in homepage instead of region page???? # separator = Frame(height=2, bd=1, relief=SUNKEN) # separator.pack(fill=X, padx=5, pady=5) Label(root, text=texts[region_number]).pack(fill=BOTH, expand=1, padx=10,pady=10) close_button = Button(root, text="Close", command=lambda:self.deleteChild(root)) close_button.pack(pady=10) # parent.after_idle(idle,parent) def deleteChild(self, w): w.destroy() @staticmethod def idle(): """ Read serial data, convert it to a number corresponding to region brain was touched return: a number from [1:5] """ # # idle routine # byte2 = 0 byte3 = 0 byte4 = 0 ser.flush() # # find framing # while 1: byte1 = byte2 byte2 = byte3 byte3 = byte4 byte4 = ord(ser.read()) if ((byte1 == 1) & (byte2 == 2) & (byte3 == 3) & (byte4 == 4)): break # ???? conver serial byte to a number and return it. HOW ???? return 0 # # check command line arguments # if (len(sys.argv) != 2): print "command line: delta.serial.ss.py serial_port" sys.exit() port = sys.argv[1] # # open serial port # ser = serial.Serial(port,9600) ser.setDTR() # # set up GUI # if __name__ == "__main__": root = Tk() main = MainWindow(root) root.title('The Instructive Brain') main.pack(side="top", fill="both", expand=True) # diff = root.after(100,idle,root) region_number = main.idle() print region main.region_page(region_number) root.mainloop()