Issuu on Google+

FAB ACADEMY 2012 FĂŠlix Libio

Interface and Application Programming


The steps to install python-tk in windows xp, w7, for Python 2.7.2

1.

Install (ActiveTcl) http://www.activestate.com/activetcl/activetcl-8-6 ActiveTcl8.5.11.1.295590-win32-ix86-threaded

2. Install (ActivePython) http://www.activestate.com/activepython-3 ActivePython-2.7.2.5-win32-x86 3. Install (Active Serial) http://sourceforge.net/projects/pyserial/ pyserial-2.5.win32

The first two are for Python-tk and the last is for Python-serial, also needs to function. install the 32 bit version, if your computer is 64 bit

• This has been done to Jesus Fabian and Henry Medina.


1. open terminal – cmd-

2. Windows terminal


3. check port

4. invoke python Python hello.light.45.py COM22


IDEA michael jackson moonwalker

imagen motion frame by frame


CHANGES IN THE INTERFACE


Explanation of Code from Tkinter import * import serial WINDOW = 1500 # window size eps = 0.5 # filter time constant filter = 0.0 # filtered value def idle(parent,canvas): global filter, eps # # idle routine # byte2 = 0 byte3 = 0 byte4 = 0 ser.flush() while 1: # # byte1 = byte2 byte2 = byte3 byte3 = byte4 byte4 = ord(ser.read()) if ((byte1 == 1) & (byte2 == 2) & (byte3 == 3) & (byte4 == 4)): break low = ord(ser.read()) high = ord(ser.read()) value = 256*high + low filter = (1-eps)*filter + eps*value x = int(.2*WINDOW + (.9-.2)*WINDOW*filter/1024.0) canvas.itemconfigure("text",text="%.1f"%filter)

x-50

canvas.coords('rect1',0*WINDOW,.001*WINDOW, ,.5*WINDOW) canvas.coords('rect2',x,0*WINDOW,.9*WINDOW,.5*WINDOW) canvas.update() parent.after_idle(idle,parent,canvas)

generates the space between the rectangles


Explanation of Code if (len(sys.argv) != 2): print "command line: hello.light.45.py serial_port" sys.exit() port = sys.argv[1] # # open serial port # ser = serial.Serial(port,9600) ser.setDTR() # # set up GUI # root = Tk() root.title('hello.light.45.py (q to exit)') root.bind('q','exit') canvas = Canvas(root, width=WINDOW, height=.25*WINDOW, background='black')

Code to add a picture. format is .gif colors of the rectangles

gif1 = PhotoImage(file = 'imagen1.gif') canvas.create_image(700,180, image = gif1) canvas.create_rectangle(0*WINDOW,.05*WINDOW,.3*WINDOW,.2*WINDOW, tags='rect1', fill='#000000') canvas.create_rectangle(.3*WINDOW,.05*WINDOW,.9*WINDOW,0*WINDOW, tags='rect2', fill='#000000')

gif2 = PhotoImage(file = 'imagen2.gif') canvas.create_image(200,180, image = gif2) canvas.create_text(.3*WINDOW,.2*WINDOW,text=".33",font=("BankGothic Md BT", 24),tags="text",fill="#FFFF24") canvas.pack() # # start idle loop # root.after(100,idle,root,canvas) root.mainloop()

thank Jesus Fabian for python classes and help with the code


Interface and Application Programming