1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
import sys
import subprocess
def testfile(filepath):
x = subprocess.Popen(["python.exe", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return x.stderr.read()
class str_stdout:
def __init__(self):
self.stdout = sys.stdout
self.buffer = ''
sys.stdout = self
def write(self, str):
self.buffer += str
def __str__(self):
return self.buffer
def close(self):
sys.stdout = self.stdout
import code
pathFile = "exemple.py"
test = testfile(pathFile)
if test:
print ('Errors found :')
print (test)
else:
console = code.InteractiveConsole()
text = []
with open(pathFile) as f:
for l in f:
l = l.rstrip()
if l:
tt = str_stdout()
text.append(">>> " + l)
console.push(l)
tt.close()
tt = str(tt).strip() # Pour éviter de récupérer des lignes vides.
if tt:
text.append(tt)
text = '\n'.join(text)
from tkinter import *
# la fenetre
fen =Tk()
fen.geometry('600x500')
# les labels
label= Label(fen,text=text,bg='grey')
label.pack(fill=X) |
Partager