I managed to mess with the provided .py code. The variables I managed to change and which I understood while changing were the most basic. Color, size, form. When I was done with my first try it looked like this:
After that I looked up some Tkinter codes
here. And I managed to have a second window open with this code:
import Tkinter
import tkMessageBox
top = Tkinter.Tk()
def helloCallBack():
tkMessageBox.showinfo( "Hall9000", "Can't let you do that Dave...")
B = Tkinter.Button(top, text ="Quit Hal9000", command = helloCallBack)
B.pack()
I don't understand why the windows open together but when you press the button another window appears with my message in there. I have tried to implement other codes but all have been unsuccesfull. This is because I have no idea why stuff works or doesn't work or what the specific codes mean. This should really be explained.
the code I used:
#
# hello.temp.45.py
#
# receive and display temperature
# hello.temp.45.py serial_port
#
# Neil Gershenfeld
# CBA MIT 3/27/12
# Variant by Rein den Hengst
# Fab Academy 4/12/13
#
# (c) Massachusetts Institute of Technology 2012
# Permission granted for experimental and personal use;
# license for commercial sale available from MIT
#
from Tkinter import *
from numpy import log
import serial
WINDOW = 1000 # window size
eps = 0.5 # filter time constant
filter = 0.0 # filtered value
def idle(parent,canvas):
global filter, eps
WINDOW = root.winfo_width()
#
# idle routine
#
byte2 = 0
byte3 = 0
byte4 = 0
ser.flush()
while 1:
#
# find framing
#
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
if (value > 511):
value -= 1024
V = 2.5 - value*5.0/(20.0*512.0) #balkje en drawing
R = 10000.0/(5.0/V-1.0)#balkje en drawing
# NHQ103B375R5
# R25 10000 (O)
# B (25/85) 3750 (K)
# R(T(C)) = R(25)*exp(B*(1/(T(C)+273.15)-(1/(25+273.15))))
B = 3750.0
R25 = 10000.0
T = 1.0/(log(R/R25)/B+(1/(20.0+273.15))) - 273.15
filter = (1-eps)*filter + eps*T
x = int(.2*WINDOW + (.9-.2)*WINDOW*(filter-20.0)/10.0)
canvas.itemconfigure("text",text="%.2f"%filter)
canvas.coords('rect1',.2*WINDOW,.05*WINDOW,x,.2*WINDOW)
canvas.coords('rect2',x,.05*WINDOW,.9*WINDOW,.2*WINDOW)
canvas.update()
parent.after_idle(idle,parent,canvas)
#
# check command line arguments
#
if (len(sys.argv) != 2):
print "command line: hello.temp.45.py serial_port"
sys.exit()
port = sys.argv[1]
#
# open serial port
#
ser = serial.Serial(port,9600)
ser.setDTR()
#
# start plotting
#
root = Tk()
root.title('Hal9000 temp (q to exit)')
root.bind('q','exit')
canvas = Canvas(root, width=WINDOW, height=.25*WINDOW, background='green')#background
canvas.create_text(.1*WINDOW,.125*WINDOW,text=".33",font=("Helvetica", 24),tags="text",fill="#000000") #changed to black
canvas.create_oval(.2*WINDOW,.05*WINDOW,.3*WINDOW,.2*WINDOW, tags='rect1', fill='#b00000')#red bar
canvas.create_oval(.3*WINDOW,.05*WINDOW,.9*WINDOW,.2*WINDOW, tags='rect2', fill='#0000b0')#blue bar
canvas.pack()
root.after(100,idle,root,canvas)
import tkMessageBox
top = Tk()
top.title('Hal9000')
def helloCallBack():
tkMessageBox.showinfo( "Hall9000", "Can't let you do that Dave...")
B = Button(top, text ="Quit Hal9000", command = helloCallBack)
B.pack()
root.mainloop()
top