【发布时间】:2020-10-15 12:22:44
【问题描述】:
我的 Tkinter GUI 不会因为循环而出现,我怎样才能在不干扰循环流的情况下使 GUI 出现?这是代码。
for record in data:
# The rest of the code...
# Datetime and auto validation for web automation
while True:
convert_time_record = datetime.datetime.strptime(record[2], '%H:%M')
date_now = datetime.datetime.now()
time_val = record[0] == date_now.strftime('%A') and convert_time_record.strftime('%H:%M:%S') == date_now.strftime('%H:%M:%S')
if time_val and record[3] == "Yes" and record[4] == "Link":
print("time true")
chrome.open(record[5])
time.sleep(5)
os.system("taskkill /im chrome.exe /f")
break
# Check if the method was by meeting ID
elif time_val and record[3] == "Yes" and record[4] == "Meeting ID":
# Open Zoom
subprocess.call("C:\\Users\\bryan\\AppData\\Roaming\\Zoom\\bin\\Zoom.exe")
time.sleep(3)
# Locate the center of the join button then move the cursor
Click('join_button.png')
time.sleep(3)
# Write the meeting id to the text field
pyautogui.write(record[5])
# Press the enter key
pyautogui.press('enter')
time.sleep(3)
# Write the passcode to the text field
pyautogui.write(record[6])
# Press the enter key
pyautogui.press('enter')
time.sleep(8)
join_computer_audio_btn = pyautogui.locateCenterOnScreen('join_audio.png')
pyautogui.moveTo(join_computer_audio_btn)
pyautogui.click()
root.mainloop()
我尝试将root.mainloop() 放在 for 循环和 while 循环中,但这会使循环无法执行函数。
【问题讨论】:
-
你的tk代码在哪里?
-
别担心,它在代码的顶部,但我不想显示我所有的代码
-
试着在循环结束时说
root.update(),由于time.sleep(),GUI仍然会冻结,请正确使用root.after(),这样GUI就不会释放。
标签: python python-3.x tkinter