首页 > 解决方案 > 是否可以使用 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 创建一个桌面应用程序来执行此任务?

该应用程序可以在我以外的其他计算机上运行吗?

您是否推荐任何其他替代方案?

标签: pythonwindowsopencvpyautogui

解决方案


感谢@The Laggy Tablet,我做了一些研究,发现了 100 多个由 John Alder 撰写的关于 Tkinter 的 youtube 视频教程。我不确定我是否可以发布链接,所以我不会,但是很容易找到。

它实际上很容易使用,当你完成它并将它变成一个实际的 GUI 时,其他人可以使用它而无需安装任何依赖项,甚至不需要安装 Python。

希望这对将来的某人有所帮助。干杯!


推荐阅读