python - 如何使用 pyautogui 简化 while 循环以实现无限循环
问题描述
我已经潜伏了一段时间,但是我看到的所有现有帖子都无法帮助我。我目前正在自学python,所以如果这是一个我没有看到的简单修复,我深表歉意。
我对这段代码的目标是使用 pyautogui.hotkey 循环浏览浏览器中的选项卡。它需要用户输入循环通过的选项卡数量,并执行 pyautogui 命令。
但是,我的问题是我无法创建循环 for 或 while 循环。
我玩过should_restart
变量for i in range(x)
等,但我只是没有看到我的修复。
下面的代码本质上是我想一起简化的。
我理想化的流程是:
取input
-> 增加tabcounter
1 直到等于input
-> 重置tabcounter
-> 冲洗并重复。
numberofTabs = input('How many tabs do you have? \n')
tabcounter = 0
while int(tabcounter) < int(numberofTabs):
tabcounter = tabcounter+1
pyautogui.hotkey('alt', str(tabcounter))
break
while int(tabcounter) == int(numberofTabs):
tabcounter = 0
我希望这段代码循环直到我中断它,或者很长一段时间。
先感谢您。感谢您的帮助!
编辑:在修改它并将我的代码包装在一个循环中之后,我想出了这个:
loopcount = input('How many times do you want this to loop?')
time.sleep(5)
count = 0
for i in range(int(loopcount)):
while count < int(numberofTabs):
count += 1
pyautogui.hotkey('alt', str(count))
time.sleep(1)
else:
count = 0```
解决方案
推荐阅读
- android - 在 Jetpack Compose 上使用 Spacer 填充剩余空间
- python - pytorch int32 到 int64 的转换
- c++ - 在 C++ 中除以负数
- angular - 如何在Angular中格式化具有特定时区的日期?
- r - devtools::install 多线程依赖
- java - DataOutputStream 第二次不工作
- django - django 组织合规性检查
- database - 通过 bash 断开 pgadmin 的连接
- java - 如何将 JSONArray 中的元素添加到 QuestionnaireItemOptionComponent 列表?
- javascript - 如果手动将 JavaScript 注入控制台但不能自动注入,则 JavaScript 可以工作