Передача текста из print в label/edit

как из значения print вывести в label?

import subprocess
from tkinter import *

root = Tk()

text = Text(width=50, height=10)
label = Label()
label.pack()
root.mainloop()


def ping():
    with open('ip.txt', 'r') as f:
        ips = f.readlines()
        index = 0
    for ip in ips:
        response = subprocess.Popen('ping -n 4 ' + ip)
        # index = ips
        if response == 0:
            print('all good')
        else:
            print('pc with index',
                  index + 1, 'off', end="\n")
    pingstatus = ping()
    return ping


if __name__ == "__main__":
    ping()

Ответы (2 шт):

Автор решения: arnold

Должно помочь:

import subprocess
from tkinter import *

root = Tk()

text = Text(width=50, height=10)

def ping():
    with open('ip.txt', 'r') as f:
        ips = f.readlines()
        index = 0
    for ip in ips:
        response = subprocess.Popen('ping -n 4 ' + ip)
        # index = ips
        if response == 0:
            label = Label(text='all good')
            label.pack()

        else:
            label = Label(text=f'pc with index {index + 1}, off')
            label.pack()
    pingstatus = ping()
    return ping


if __name__ == "__main__":
    ping()
    root.mainloop()
→ Ссылка
Автор решения: Сергей

Запускать ping лучше кнопкой.

from tkinter import *




def ping():
    with open('ip.txt', 'r') as f:
        ips = f.readlines()
        index = 0
    for ip in ips:
        response = subprocess.Popen('ping -n 4 ' + ip)
        # index = ips
        if response == 0:
            label.config(text='all good')
        else:
            label.config(text=f'pc with index {index + 1} off \n')
    pingstatus = ping()
    return ping


if __name__ == "__main__":
    root = Tk()

    text = Text(root, width=50, height=10)
    text.pack()
    label = Label(root, text='answer')
    label.pack()
    button = Button(root, text='Старт ping', command=ping)
    button.pack()
    root.mainloop()
→ Ссылка