Python脚本、.py或文本文件,输出到tinter gui

2024-05-23 17:06:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了一个带有按钮的tkinter gui,按下按钮后,它们在终端中执行一个.py文件。py文件使用代码中的文本文件生成图形,因此它并不总是固定的图像。因此,每次选择按钮并生成新的图形图像时,它都需要出现在gui上。你知道吗

有没有一种方法可以让输出到gui而不是在终端上显示它?你知道吗

我的代码:

def visualise():
    with open(example.png, "w") as output:
        command = ("python graph.py")
        p = subprocess.Popen(command, stdout=output, stderr=output, shell=True)

buttongraph = Tkinter.Button(self, text="generate graph", command=visualise)
buttongraph.pack()

Tags: 文件代码py图像终端图形outputvisualise