[英]Tkinter: GUI won't appear because of loops
由於循環,我的 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 循環中,但這會使循環無法執行該函數。
您應該只運行root.mainloop()
一次。 使用循環會阻止 GUI 更新,因此考慮使用不同的線程來運行循環並將更新從另一個線程發送到 GUI,或者使用一個對象來維護循環的狀態並使用非阻塞函數來獲取狀態對象並讓它更新並使用 tkinter 的 after 函數重新設置調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.