我正在尝试在 Python 中创建一个 GUI,它将接受 bash 命令并显示所有内容,包括图形输出

I'm trying to create a GUI in Python which would accept a bash command and would display everything including graphical outputs

提问人:user22758952 提问时间:11/13/2023 最后编辑:user22758952 更新时间:11/13/2023 访问量:32

问:

我正在尝试在 Python 中创建一个 GUI,它将接受这样的 bash 命令并显示此命令的所有输出,包括任何图形python OK21.py

如果我从命令行运行这个python OK21.py

它确实这样做了,但是当尝试从 GUI 执行此操作时,如下所示:

# import required modules
import os
import pyautogui

# prompts message on screen and gets the command
# value in val variable
value = pyautogui.prompt("Enter Shell Command")

# executes the command and returns 
# the output in stream variable
stream = os.popen(value)

# reads the output from stream variable
out = stream.read()
pyautogui.alert(out)

它仅显示文本输出,省略了存在的图形窗口编辑 最好的解决方案是在不将任何图像保存到文件的情况下执行此操作。但是,如果这可以自动完成,这对我来说可能是一个很好的解决方案。 此外,由于某些原因,我有并且无法升级。pngpython 3.6.13

python-3.x 用户界面 pyautogui

评论

0赞 Mark Ransom 11/13/2023
图形输出不通过正常的控制台界面,因此 Python 没有捕获它们的机制。您需要使用一个模块来查找并执行这些图形窗口的屏幕截图。
0赞 user22758952 11/13/2023
@MarkRansom 可能是哪个模块?
0赞 Mark Ransom 11/13/2023
如果我知道,我会留下答案。Pyautogui 可能有一些能力,至少在寻找窗口方面是这样。
0赞 user22758952 11/13/2023
@MarkRansom 这样一个显而易见和基本的事情不应该没有一个简单的解决方案吗?
0赞 user22758952 11/13/2023
如果我还没有显示窗口,我该如何做到这一点:?screen captureimport pyautogui im1 = pyautogui.screenshot() im1.save(r"C:/Users/Hynek/Desktop/Untitled.png")

答: 暂无答案