为外部脚本编写UI如何使用stdout方法将要打印的外部脚本中的打印重定向到标签上?

问题描述

这是我编写的当前UI脚本...

import tkinter as ttk
import subprocess
import sys
import time
import os
import tkinter.font as font
from tkinter.ttk import *

app = ttk.Tk()

app.geometry("400x400")
app.configure(bg='gray')

photo = ttk.PhotoImage(file=r"C:\Users\ex\ex_button_active.png")
myFont = font.Font(family='Helvetica',size=20,weight='normal')

ttk.Label(app,text='Ex',bg='gray',font=(
    'Verdana',15)).pack(side=ttk.TOP,pady=10)
app.iconbitmap(r'C:\Users\ex\ex_icon.ico')


def ex_activation():
    global pro
    print("Running program!")
    pro = subprocess.Popen("python programex.py",shell=True)


def ex_stop():
    global pro
    print("Stopping Program... Please Wait!")
    os.kill(pro.pid,0)


ex_activation_button = ttk.Button(app,bg='black',image=photo,width=120,height=120,command=ex_activation)

ex_stop_button = ttk.Button(app,bg='Gray',text='Stop Program',width=12,command=ex_stop,height=3)

ex_stop_button['font'] = myFont

app.title("Ex")
ex_activation_button.pack(side=ttk.TOP)
ex_stop_button.pack(side=ttk.LEFT)

# app.mainloop()
while True:
    try:
        app.update()
        app.update_idletasks()
    except KeyboardInterrupt:
        pass

我一直在处理我提出的其他一些问题。之所以不同,是因为这个问题仅集中在使用stdout方法上。主要目标是从外部脚本中提取 ANY 打印语句,并将它们逐行打印到tkinter标签上。我想使用stdout方法Here is a post I Had Found that May Help预先感谢任何可以帮助我实现这一目标的人。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)