我是python的新手,目前正尝试使用tkinker制作一个倒数计时器GUI,并且将来会与Arduino集成,以下是我的代码的一部分,它以分钟和秒为输入,并试图显示窗内还剩下多少时间
import tkinter as tk
import serial, time
from time import sleep
import sys, os
window = tk.Tk()
window.title('Stimulation App')
window.geometry('800x600')
window.configure(background='white')
header_label = tk.Label(window, text='start')
header_label.pack()
minutes_frame = tk.Frame(window)
minutes_frame.pack(side=tk.TOP)
minutes_label = tk.Label(minutes_frame, text='minutes')
minutes_label.pack(side=tk.LEFT)
minute_entry = tk.Entry(minutes_frame)
minute_entry.pack(side=tk.LEFT)
seconds_frame = tk.Frame(window)
seconds_frame.pack(side=tk.TOP)
seconds_label = tk.Label(seconds_frame, text='seconds')
seconds_label.pack(side=tk.LEFT)
second_entry = tk.Entry(seconds_frame)
second_entry.pack(side=tk.LEFT)
result_label = tk.Label(window)
result_label.pack()
try:
def countdown(i,j):
i=int(minute_entry.get())
j=int(second_entry.get())
k=0
while True:
if(j==-1):
j=59
i -=1
if(j > 9):
print(str(k)+str(i)+":"+str(j), end="\r")
else:
print(str(k)+str(i)+":"+str(k)+str(j), end="\r")
time.sleep(1)
j -= 1
if(i==0 and j==-1):
break
if(i==0 and j==-1):
time.sleep(1)
countdown(int(minute_entry.get()),int(second_entry.get())) #countdown(min,sec)
except KeyboardInterrupt:
ser.close()
print('\n interrupted')
calculate_btn = tk.Button(window, text='start', command=countdown)
calculate_btn.pack()
window.mainloop()
但是以某种方式我无法将输入信息输入倒数,我的代码出了什么问题?