# -*- coding: utf-8 -*-
#!/usr/bin/env python2
import sys
import os
from Tkinter import * # 导入 Tkinter 库
import time
import threading
root = Tk() # 初始化Tk()
root.title("GUI-Test-Read thermal") # 设置窗口标题
root.geometry("500x300") # 设置窗口大小 注意:是x 不是*
root.resizable(width=False, height=False) # 设置窗口是否可以变化长/宽,False不可变,True可变,默认为True
#root.iconbitmap('\heat.ico')
li = ['1','2','3','4','5','6']
#movie = ['7','8','9']
listb = Listbox(root)
#listb2 = Listbox(root)
for item in li:
listb.insert(0,item)
#for item in movie:
# listb2.insert(0,item)
def SaveLogfile(Str):
f=open('.\\GUI_log.txt','a+')
print>>f,Str
f.close()
def addlist():
if listb.get(0)=="":
a=int("0")
else:
a=int(listb.get(0))
a=a+1;
listb.insert(0,str(a))
# if a==15:
# listb2.destroy()
if a==22:
#listb.clear
listb.delete(0,END)
if a==90:
root.destroy()
def Button1cmd():
#listb.delete(0,END)
Tstr=time.strftime('%m/%d-%H:%M:%S',time.localtime(time.time()))
listb.insert(0,Tstr)
SaveLogfile(Tstr)
def Button2cmd():
root.destroy()
def Button3cmd():
Tstr=time.strftime('%m/%d-%H:%M:%S',time.localtime(time.time()))
listb.insert(0,Tstr)
var1 = IntVar()
Checkbutton(root, text="Auto_Raed", variable=var1).place(x=6, y=40)
def fun_timer():
button1.place(x=6, y=130)
if var1.get()==1:
Button3cmd();
global timer
timer = threading.Timer(2.0, fun_timer)
timer.start()
timer = threading.Timer(1, fun_timer)
timer.start()
v1 = StringVar()
p1 = StringVar()
def Button4cmd():
if ''==v1.get():
return;
if ''==p1.get():
return;
print (v1.get())
print (p1.get())
############################################################################### grid
def get_screen_size(window):
return window.winfo_screenwidth(),window.winfo_screenheight()
def get_window_size(window):
return window.winfo_reqwidth(),window.winfo_reqheight()
def center_window(root, width, height):
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)
#print(size)
root.geometry(size)
center_window(root, 800,500)
###############################################################################
Button(root, text="press_Read", command=addlist).place(x=6, y=60)
button1 = Button(root, text="press_Clear", command=Button1cmd)
button1.place(x=6, y=130)
button4 = Button(root, text="get-value", command=Button4cmd)
button4.place(x=280, y=460)
button3 = Button(root, text="Set-Timer", command=Button3cmd)
button3.place(x=6, y=180)
button2 = Button(root, text="press_Exit", command=Button2cmd)
button2.place(x=6, y=280)
listb.place(x=100, y=6, height=380, width=490)
#listb2.grid(column=30, row=0)
def test(content):
if content.isdigit() or content == "":
return True
else:
return False
test_cmd = root.register(test)
Label1 = Label(root,text='Input Fan 1 speed:').place(x=8,y=430)
Label2 = Label(root,text='Input Fan 2 speed:').place(x=8,y=460)
e1 = Entry(root,textvariable=v1,
validate='key',
validatecommand=(test_cmd, '%P') ).place(x=120,y=430)
e2 = Entry(root,textvariable=p1,
validate='key',
validatecommand=(test_cmd, '%P') ).place(x=120,y=460)
root.mainloop()