悠龠111 发表于 2020-5-19 22:09:42

关于时间戳问题

为什么While函数里面的那个time.time() - begintime >=1,begintime为什么要自增1?

def auto_selectthree(begintime): #自制不精确的计时器,线程函数
    global label_auto
    global autoflag
    try:
      duration = int(input_time.get())
    except:
      tk.messagebox.showerror("错误!","您输入的不是整数")
      return
    if (autoflag ==1):
      btn_next_click()
    else:
      pass
    while (autoflag == 1):
      if (time.time() - begintime >= 1 and duration > 0):
            begintime = begintime + 1
            duration = duration - 1
            label_auto["text"] = str(duration) + "秒后自动"
      elif (duration <= 0):
            label_auto["text"] = "查询数据中..."
            btn_next_click()
            duration = int(input_time.get())
            begintime = time.time()
            label_auto["text"] = str(duration) + "秒后自动"
      else:
            pass
    label_auto["text"] = "已停止"


def btn_start_clickthree():
    global label_path
    global photo_repository
    if (len(photo_repository) == 0):
      tk.messagebox.showinfo("警告", "先选择照片所在的文件夹!")
    else:
      global autoflag
      global auto_selectthree
      if (autoflag == True):
            pass
      else:
            import threading
            autoflag = 1
            label_auto["text"] = input_time.get()+"秒后自动"
            threading._start_new_thread(auto_selectthree, (time.time(),))#auto_selectthree为线程函数,time.time()为传给线程函数的参数


def btn_stop_click():
    global autoflag
    global label_auto
    autoflag = 0
    label_auto["text"] = "已停止"

_荟桐_ 发表于 2020-5-19 22:40:57

while不是函数吧

悠龠111 发表于 2020-5-20 08:57:57

有人吗?
页: [1]
查看完整版本: 关于时间戳问题