python - 是否可以使用 python 和导入的库创建桌面应用程序?
问题描述
我是编码的初学者。我使用 python 和 windows 10
我编写了一个非常简单的代码,它捕获然后打开一个图像,然后循环匹配模板,以便使用包含所有可能答案的列表来确定该图像中的对象是什么。代码使用pyautogui和opencv:
import pyautogui
import cv2 as cv
def my_func():
#train image
pyautogui.screenshot("train.png") #I am looking at the picture of an animal and the robot takes a screenshot and stores it.
train_img = cv.imread("train.png", 0)
#Contains all the images to iterate through
template_list = ["apple.png", "person.png", "animal.png"]
for i in template_list:
#template image
template_img = cv.imread(i,0)
#match template
result = cv.matchTemplate(train_img, template_img, cv.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)
if max_val >= .85:
print(i) #prints the name of the matched image
return True
print("could not match the train image to one of the available templates.")
return False
预期的输出仅供控制台打印:
animal.png
我想创建一个应用程序、一个窗口或任何类似的东西,您可以在其中单击一个显示“运行”的按钮,然后代码就会运行。完成后,它将显示控制台日志。
您可以通过 VS Code 执行此操作,但是在代码运行时,我看不到控制台日志(因为我需要转到将截屏的图像)并且我希望能够看到它。
所以我的问题是:
是否可以为 Windows 创建一个桌面应用程序来执行此任务?
该应用程序可以在我以外的其他计算机上运行吗?
您是否推荐任何其他替代方案?
解决方案
感谢@The Laggy Tablet,我做了一些研究,发现了 100 多个由 John Alder 撰写的关于 Tkinter 的 youtube 视频教程。我不确定我是否可以发布链接,所以我不会,但是很容易找到。
它实际上很容易使用,当你完成它并将它变成一个实际的 GUI 时,其他人可以使用它而无需安装任何依赖项,甚至不需要安装 Python。
希望这对将来的某人有所帮助。干杯!
推荐阅读
- firebase - 如何限制 Cloud Firestore 安全规则
- matlab - 单元格作为带有 cell2table 的标题 - Matlab
- python - 使用 LSTM 预测 2 的乘法序列中的下一项
- python - 我应该如何在 Stack Overflow 帖子中发布我的 juptyer 笔记本中的 DataFrame 输出?
- python - Python 级联命令
- python - Tensorflow 2 -概率:ValueError:无法将 NumPy 数组转换为张量(不支持的 numpy 类型:NPY_INT)
- scala - Scala Spark Dataframe 创建一个新列,其中包含另一列的最大先前值和当前值
- python - PyQt5:如何通过传递引用/值来检查我的文本框是否为空?
- java - 如何在不嵌套特定标签的情况下将 EditText 转换为 html
- python - Django - 部署 DigitalOcean 问题 - python collectstatic