Widget to Display subprocess stdout?

前端 未结 1 424
春和景丽
春和景丽 2020-12-18 15:05

I have a python based tkinter script which executes some commands using subprocess module. I need to display the standard output on the GUI itself. Since I am new to tk (One

相关标签:
1条回答
  • 2020-12-18 16:02

    You may want to use the Tkinter.Text widget, described here.

    The description is quite long, but what you need to understand is mainly that this widget can be used as a buffer, as text should be inserted inside.

    So, for each new line in the subprocess output, you will have to insert text where you want it. Example:

    t = Tkinter.Text(root)
    while some_condition:
        s = p.readline()          # get subprocess output
        t.insert(END, s)
    

    EDIT Have a look here for getting subprocess output line by line.

    You may also want to have a look to Tkinter.Scrollbar and Text.see() to tune the display.

    0 讨论(0)
提交回复
热议问题