python - 屏幕评估问题和简单的 if 语句
问题描述
我是stackoverflow的新手,但有一个愚蠢的问题:
如果我打开命令提示符,我想让我的电脑做某事。我有其他计划,但目前它只是打印出来是否打开。为什么这段代码不起作用???计算机甚至打印出触发值(12、12、12)。我的 if 语句有问题吗?
提前致谢
输出:
12.12.12
command prompt not opened
12.12.12
command prompt not opened
12.12.12
command prompt not opened
12.12.12
command prompt not opened
12.12.12
command prompt not opened
12.12.12
command prompt not opened
12.12.12
command prompt not opened
12.12.12
command prompt not opened
from PIL import ImageGrab, Image
import time
pixel = (1713, 978) #pixel for evaluation
while True:
img = ImageGrab.grab() #grabs image (like a screenshot)
color = img.getpixel(pixel) #reads colors of this pixel
red = str(color[0]) #saves colors in three variables to make evaluation easier
green = str(color[1])
blue = str(color[2])
print(red + "." + green + "." + blue) #prints color in rgb
if red == 12 and green == 12 and blue == 12: #if all three colors are 12 -> print that cmd is opened
print("command promt opened")
time.sleep(5)
else: #else print that cmd isn't opened
print("command prompt not opened")```
解决方案
这是解决方案:
if int(red) == 12 and int(green) == 12 and int(blue) == 12:
推荐阅读
- pyqt - 此线程上没有运行事件循环
- angular - 如何在Angular Service中动态地将参数添加到url
- python - 如何在 sklearn cross_val_score 中使用自定义评分功能
- javascript - Typescript 找不到使用 webpack 别名导入的模块
- r - if 内嵌套 ifelse 语句
- ios - Unity 集成本机应用程序中的 Clang 错误
- shell - 从任务的输出中获取一个值并在 Ansible Playbook 中调试消息
- macos - OSX:关闭 mysql 工作台主窗口后无法打开它
- python - 从opencv中的二维索引数组获取矩形
- html - How to format json file view on html