从输入框返回值以启动感测帽计时器

时间:2017-12-22 11:50:13

标签: python tkinter

我正在尝试启动倒数计时器以显示感测帽,当我运行代码时它没有输入值输入到输入框而没有返回错误只是在感应帽上显示0

from sense_hat import SenseHat
from tkinter import *   

#set up
window = Tk()
window.title('timer')
window.geometry("300x100") #wxh
window.resizable(0,0)


#define and place labels
box1 = Label(window, text="time: ")
box1.grid(row = 1, column = 1,padx = 5, pady = 5)

#define entry box
answerVar = IntVar()
answertext = Entry(window,textvariable=answerVar)
string_answer = answertext.get()
int_answer = int(string_answer)


#display boxes
answertext.grid(row = 1, column = 2)

#define and place buttons
buttonstart = Button( window,text ='start:', command=lambda:int_answer)

sense = SenseHat()

G = [128,0,128]  #led color    
for i in range(int_answer,-1,-1): #create range start from input, stop at 
                                  #0 is -1
#decrease in steps is -1  Range is only a number

    sense.show_letter(str(i),G) 

exitbtn = Button( window,text ='Exit', command=exit)

#place buttons
buttonstart.grid(row = 4, column = 1,padx = 1, pady = 1)
exitbtn.grid(row = 4, column = 2,padx = 1, pady = 1)


#display window
window.mainloop()

0 个答案:

没有答案