如何将终端输出重定向到tkinter GUI

2024-10-02 20:37:18 发布

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

我无法获取从终端到tkinter标签小部件的输出。有人能帮我吗

班级安排管理:

def __init__(self, masterwindow, title, size):
    self.masterwindow = masterwindow

     self.button_showobj = Button(self.frame1, text=' Show Object ', fg='black', bg='light yellow',
                            command=lambda: self.callback1(),
                            height=1, width=11)
    self.button_showobj.grid(row=3, column=3)

    self.lableshow=Label(self.frame1, text='', font=("Times NewRoman", 10)).grid(column=1, row=4,
                                                                                               padx=10,
                                                                                               pady=25)
    self.showobj=StringVar()

def callback1(self):
    cmd = 'python test.py'
    
    output = subprocess.check_output(cmd, shell=True)
    self.lableshow['text'] = self.showobj
    
   

Tags: textselfcmd终端outputdefcolumnbutton