Add the text output from the console to the PyQT window
How do I display the text output from the console to the PyQT dialog box along with the generated graph?
The code below runs a heart disease predictor program and its results are presented by a graph that is generated and shown in the PyQT window. However, we also need the interpretation of the results to be displayed in the dialog box but we can't seem to figure it out. Please help.
import sys
from PyQt5.QtWidgets import QDialog, QApplication, QPushButton, QVBoxLayout
from numpy import genfromtxt
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from sklearn.svm import LinearSVC
from sklearn.decomposition import PCA
import pylab as pl
from itertools import cycle
from sklearn import cross_validation
from sklearn.svm import SVC
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
import random
class Window(QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to `plot` method
self.button = QPushButton('Plot the data')
self.button.clicked.connect(self.my_model)
# set the layout
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
self.setLayout(layout)
#Method to plot the graph for reduced Dimesions
def plot_2D(self,data, target, target_names,ax):
colors = cycle('rgbcmykw')
target_ids = range(len(target_names))
for i, c, label in zip(target_ids, colors, target_names):
ax.scatter(data[target == i, 0], data[target == i, 1],
c=c, label=label)
plt.legend()
plt.savefig('Reduced_PCA_Graph')
def my_model(self):
''' plot some random stuff '''
#Loading and pruning the data
dataset = genfromtxt('cleveland_data.csv',dtype = float, delimiter=',')
#print dataset
X = dataset[:,0:12] #Feature Set
y = dataset[:,13] #Label Set
# Classifying the data using a Linear SVM and predicting the probability of disease belonging to a particular class
modelSVM = LinearSVC(C=0.001)
pca = PCA(n_components=5, whiten=True).fit(X)
X_new = pca.transform(X)
# calling plot_2D
target_names = ['0','1','2','3','4']
# create an axis
ax = self.figure.add_subplot(111)
# discards the old graph
ax.clear()
self.plot_2D(X_new, y, target_names,ax)
# refresh canvas
self.canvas.draw()
#Applying cross validation on the training and test set for validating our Linear SVM Model
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X_new, y, test_size=0.4, train_size=0.6, random_state=0)
modelSVM = modelSVM.fit(X_train, y_train)
print("Testing Linear SVC values using Split")
print(modelSVM.score(X_test, y_test))
# printing the Likelihood of disease belonging to a particular class
# predicting the outcome
count0 = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0
for i in modelSVM.predict(X_new):
if i == 0:
count0 = count0+1;
elif i == 1:
count1 = count1+1;
elif i == 2:
count2 = count2+1;
elif i == 3:
count3 = count3+1;
elif modelSVM.predict(i) ==4:
count4 = count4+1
total = count0+count1+count2+count3+count4
#Predicting the Likelihood
#Applying the Principal Component Analysis on the data features
modelSVM2 = SVC(C=0.001,kernel='rbf')
#Applying cross validation on the training and test set for validating our Linear SVM Model
X_train1, X_test1, y_train1, y_test1 = cross_validation.train_test_split(X_new, y, test_size=0.4, train_size=0.6, random_state=0)
modelSVM2 = modelSVM2.fit(X_train1, y_train1)
print("Testing with RBF using split")
print(modelSVM2.score(X_test1, y_test1))
#Using Stratified K Fold
skf = cross_validation.StratifiedKFold(y, n_folds=5)
for train_index, test_index in skf:
# print("TRAIN:", train_index, "TEST:", test_index)
X_train3, X_test3 = X[train_index], X[test_index]
y_train3, y_test3 = y[train_index], y[test_index]
modelSVM3 = SVC(C=0.001,kernel='rbf')
modelSVM3 = modelSVM3.fit(X_train3, y_train3)
print("Testing using stratified with K folds")
print(modelSVM3.score(X_test3, y_test3))
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Window()
main.show()
sys.exit(app.exec_())
The code above outputs the predictor graph in a dialog box, now all we need is its text interpretation to be displayed
python user-interface pyqt pyqt5 spyder
add a comment |
How do I display the text output from the console to the PyQT dialog box along with the generated graph?
The code below runs a heart disease predictor program and its results are presented by a graph that is generated and shown in the PyQT window. However, we also need the interpretation of the results to be displayed in the dialog box but we can't seem to figure it out. Please help.
import sys
from PyQt5.QtWidgets import QDialog, QApplication, QPushButton, QVBoxLayout
from numpy import genfromtxt
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from sklearn.svm import LinearSVC
from sklearn.decomposition import PCA
import pylab as pl
from itertools import cycle
from sklearn import cross_validation
from sklearn.svm import SVC
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
import random
class Window(QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to `plot` method
self.button = QPushButton('Plot the data')
self.button.clicked.connect(self.my_model)
# set the layout
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
self.setLayout(layout)
#Method to plot the graph for reduced Dimesions
def plot_2D(self,data, target, target_names,ax):
colors = cycle('rgbcmykw')
target_ids = range(len(target_names))
for i, c, label in zip(target_ids, colors, target_names):
ax.scatter(data[target == i, 0], data[target == i, 1],
c=c, label=label)
plt.legend()
plt.savefig('Reduced_PCA_Graph')
def my_model(self):
''' plot some random stuff '''
#Loading and pruning the data
dataset = genfromtxt('cleveland_data.csv',dtype = float, delimiter=',')
#print dataset
X = dataset[:,0:12] #Feature Set
y = dataset[:,13] #Label Set
# Classifying the data using a Linear SVM and predicting the probability of disease belonging to a particular class
modelSVM = LinearSVC(C=0.001)
pca = PCA(n_components=5, whiten=True).fit(X)
X_new = pca.transform(X)
# calling plot_2D
target_names = ['0','1','2','3','4']
# create an axis
ax = self.figure.add_subplot(111)
# discards the old graph
ax.clear()
self.plot_2D(X_new, y, target_names,ax)
# refresh canvas
self.canvas.draw()
#Applying cross validation on the training and test set for validating our Linear SVM Model
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X_new, y, test_size=0.4, train_size=0.6, random_state=0)
modelSVM = modelSVM.fit(X_train, y_train)
print("Testing Linear SVC values using Split")
print(modelSVM.score(X_test, y_test))
# printing the Likelihood of disease belonging to a particular class
# predicting the outcome
count0 = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0
for i in modelSVM.predict(X_new):
if i == 0:
count0 = count0+1;
elif i == 1:
count1 = count1+1;
elif i == 2:
count2 = count2+1;
elif i == 3:
count3 = count3+1;
elif modelSVM.predict(i) ==4:
count4 = count4+1
total = count0+count1+count2+count3+count4
#Predicting the Likelihood
#Applying the Principal Component Analysis on the data features
modelSVM2 = SVC(C=0.001,kernel='rbf')
#Applying cross validation on the training and test set for validating our Linear SVM Model
X_train1, X_test1, y_train1, y_test1 = cross_validation.train_test_split(X_new, y, test_size=0.4, train_size=0.6, random_state=0)
modelSVM2 = modelSVM2.fit(X_train1, y_train1)
print("Testing with RBF using split")
print(modelSVM2.score(X_test1, y_test1))
#Using Stratified K Fold
skf = cross_validation.StratifiedKFold(y, n_folds=5)
for train_index, test_index in skf:
# print("TRAIN:", train_index, "TEST:", test_index)
X_train3, X_test3 = X[train_index], X[test_index]
y_train3, y_test3 = y[train_index], y[test_index]
modelSVM3 = SVC(C=0.001,kernel='rbf')
modelSVM3 = modelSVM3.fit(X_train3, y_train3)
print("Testing using stratified with K folds")
print(modelSVM3.score(X_test3, y_test3))
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Window()
main.show()
sys.exit(app.exec_())
The code above outputs the predictor graph in a dialog box, now all we need is its text interpretation to be displayed
python user-interface pyqt pyqt5 spyder
I guess you can find ideas in that question: stackoverflow.com/questions/8356336/…
– Astrom
Jan 19 at 19:58
Possible duplicate of How to capture output of Python's interpreter and show in a Text widget?
– Isma
Jan 20 at 10:21
add a comment |
How do I display the text output from the console to the PyQT dialog box along with the generated graph?
The code below runs a heart disease predictor program and its results are presented by a graph that is generated and shown in the PyQT window. However, we also need the interpretation of the results to be displayed in the dialog box but we can't seem to figure it out. Please help.
import sys
from PyQt5.QtWidgets import QDialog, QApplication, QPushButton, QVBoxLayout
from numpy import genfromtxt
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from sklearn.svm import LinearSVC
from sklearn.decomposition import PCA
import pylab as pl
from itertools import cycle
from sklearn import cross_validation
from sklearn.svm import SVC
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
import random
class Window(QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to `plot` method
self.button = QPushButton('Plot the data')
self.button.clicked.connect(self.my_model)
# set the layout
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
self.setLayout(layout)
#Method to plot the graph for reduced Dimesions
def plot_2D(self,data, target, target_names,ax):
colors = cycle('rgbcmykw')
target_ids = range(len(target_names))
for i, c, label in zip(target_ids, colors, target_names):
ax.scatter(data[target == i, 0], data[target == i, 1],
c=c, label=label)
plt.legend()
plt.savefig('Reduced_PCA_Graph')
def my_model(self):
''' plot some random stuff '''
#Loading and pruning the data
dataset = genfromtxt('cleveland_data.csv',dtype = float, delimiter=',')
#print dataset
X = dataset[:,0:12] #Feature Set
y = dataset[:,13] #Label Set
# Classifying the data using a Linear SVM and predicting the probability of disease belonging to a particular class
modelSVM = LinearSVC(C=0.001)
pca = PCA(n_components=5, whiten=True).fit(X)
X_new = pca.transform(X)
# calling plot_2D
target_names = ['0','1','2','3','4']
# create an axis
ax = self.figure.add_subplot(111)
# discards the old graph
ax.clear()
self.plot_2D(X_new, y, target_names,ax)
# refresh canvas
self.canvas.draw()
#Applying cross validation on the training and test set for validating our Linear SVM Model
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X_new, y, test_size=0.4, train_size=0.6, random_state=0)
modelSVM = modelSVM.fit(X_train, y_train)
print("Testing Linear SVC values using Split")
print(modelSVM.score(X_test, y_test))
# printing the Likelihood of disease belonging to a particular class
# predicting the outcome
count0 = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0
for i in modelSVM.predict(X_new):
if i == 0:
count0 = count0+1;
elif i == 1:
count1 = count1+1;
elif i == 2:
count2 = count2+1;
elif i == 3:
count3 = count3+1;
elif modelSVM.predict(i) ==4:
count4 = count4+1
total = count0+count1+count2+count3+count4
#Predicting the Likelihood
#Applying the Principal Component Analysis on the data features
modelSVM2 = SVC(C=0.001,kernel='rbf')
#Applying cross validation on the training and test set for validating our Linear SVM Model
X_train1, X_test1, y_train1, y_test1 = cross_validation.train_test_split(X_new, y, test_size=0.4, train_size=0.6, random_state=0)
modelSVM2 = modelSVM2.fit(X_train1, y_train1)
print("Testing with RBF using split")
print(modelSVM2.score(X_test1, y_test1))
#Using Stratified K Fold
skf = cross_validation.StratifiedKFold(y, n_folds=5)
for train_index, test_index in skf:
# print("TRAIN:", train_index, "TEST:", test_index)
X_train3, X_test3 = X[train_index], X[test_index]
y_train3, y_test3 = y[train_index], y[test_index]
modelSVM3 = SVC(C=0.001,kernel='rbf')
modelSVM3 = modelSVM3.fit(X_train3, y_train3)
print("Testing using stratified with K folds")
print(modelSVM3.score(X_test3, y_test3))
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Window()
main.show()
sys.exit(app.exec_())
The code above outputs the predictor graph in a dialog box, now all we need is its text interpretation to be displayed
python user-interface pyqt pyqt5 spyder
How do I display the text output from the console to the PyQT dialog box along with the generated graph?
The code below runs a heart disease predictor program and its results are presented by a graph that is generated and shown in the PyQT window. However, we also need the interpretation of the results to be displayed in the dialog box but we can't seem to figure it out. Please help.
import sys
from PyQt5.QtWidgets import QDialog, QApplication, QPushButton, QVBoxLayout
from numpy import genfromtxt
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from sklearn.svm import LinearSVC
from sklearn.decomposition import PCA
import pylab as pl
from itertools import cycle
from sklearn import cross_validation
from sklearn.svm import SVC
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
import random
class Window(QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to `plot` method
self.button = QPushButton('Plot the data')
self.button.clicked.connect(self.my_model)
# set the layout
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
self.setLayout(layout)
#Method to plot the graph for reduced Dimesions
def plot_2D(self,data, target, target_names,ax):
colors = cycle('rgbcmykw')
target_ids = range(len(target_names))
for i, c, label in zip(target_ids, colors, target_names):
ax.scatter(data[target == i, 0], data[target == i, 1],
c=c, label=label)
plt.legend()
plt.savefig('Reduced_PCA_Graph')
def my_model(self):
''' plot some random stuff '''
#Loading and pruning the data
dataset = genfromtxt('cleveland_data.csv',dtype = float, delimiter=',')
#print dataset
X = dataset[:,0:12] #Feature Set
y = dataset[:,13] #Label Set
# Classifying the data using a Linear SVM and predicting the probability of disease belonging to a particular class
modelSVM = LinearSVC(C=0.001)
pca = PCA(n_components=5, whiten=True).fit(X)
X_new = pca.transform(X)
# calling plot_2D
target_names = ['0','1','2','3','4']
# create an axis
ax = self.figure.add_subplot(111)
# discards the old graph
ax.clear()
self.plot_2D(X_new, y, target_names,ax)
# refresh canvas
self.canvas.draw()
#Applying cross validation on the training and test set for validating our Linear SVM Model
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X_new, y, test_size=0.4, train_size=0.6, random_state=0)
modelSVM = modelSVM.fit(X_train, y_train)
print("Testing Linear SVC values using Split")
print(modelSVM.score(X_test, y_test))
# printing the Likelihood of disease belonging to a particular class
# predicting the outcome
count0 = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0
for i in modelSVM.predict(X_new):
if i == 0:
count0 = count0+1;
elif i == 1:
count1 = count1+1;
elif i == 2:
count2 = count2+1;
elif i == 3:
count3 = count3+1;
elif modelSVM.predict(i) ==4:
count4 = count4+1
total = count0+count1+count2+count3+count4
#Predicting the Likelihood
#Applying the Principal Component Analysis on the data features
modelSVM2 = SVC(C=0.001,kernel='rbf')
#Applying cross validation on the training and test set for validating our Linear SVM Model
X_train1, X_test1, y_train1, y_test1 = cross_validation.train_test_split(X_new, y, test_size=0.4, train_size=0.6, random_state=0)
modelSVM2 = modelSVM2.fit(X_train1, y_train1)
print("Testing with RBF using split")
print(modelSVM2.score(X_test1, y_test1))
#Using Stratified K Fold
skf = cross_validation.StratifiedKFold(y, n_folds=5)
for train_index, test_index in skf:
# print("TRAIN:", train_index, "TEST:", test_index)
X_train3, X_test3 = X[train_index], X[test_index]
y_train3, y_test3 = y[train_index], y[test_index]
modelSVM3 = SVC(C=0.001,kernel='rbf')
modelSVM3 = modelSVM3.fit(X_train3, y_train3)
print("Testing using stratified with K folds")
print(modelSVM3.score(X_test3, y_test3))
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Window()
main.show()
sys.exit(app.exec_())
The code above outputs the predictor graph in a dialog box, now all we need is its text interpretation to be displayed
python user-interface pyqt pyqt5 spyder
python user-interface pyqt pyqt5 spyder
asked Jan 19 at 9:24
KatKat
43
43
I guess you can find ideas in that question: stackoverflow.com/questions/8356336/…
– Astrom
Jan 19 at 19:58
Possible duplicate of How to capture output of Python's interpreter and show in a Text widget?
– Isma
Jan 20 at 10:21
add a comment |
I guess you can find ideas in that question: stackoverflow.com/questions/8356336/…
– Astrom
Jan 19 at 19:58
Possible duplicate of How to capture output of Python's interpreter and show in a Text widget?
– Isma
Jan 20 at 10:21
I guess you can find ideas in that question: stackoverflow.com/questions/8356336/…
– Astrom
Jan 19 at 19:58
I guess you can find ideas in that question: stackoverflow.com/questions/8356336/…
– Astrom
Jan 19 at 19:58
Possible duplicate of How to capture output of Python's interpreter and show in a Text widget?
– Isma
Jan 20 at 10:21
Possible duplicate of How to capture output of Python's interpreter and show in a Text widget?
– Isma
Jan 20 at 10:21
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54265683%2fadd-the-text-output-from-the-console-to-the-pyqt-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54265683%2fadd-the-text-output-from-the-console-to-the-pyqt-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I guess you can find ideas in that question: stackoverflow.com/questions/8356336/…
– Astrom
Jan 19 at 19:58
Possible duplicate of How to capture output of Python's interpreter and show in a Text widget?
– Isma
Jan 20 at 10:21