因此,我试图创建一个简单的pyscript编辑器,我想将控制台输出放入tkinter wiondow内部的标签中
到目前为止,这是我的代码,谢谢!
from tkinter import Text, Tk
import os
root = Tk()
root.configure(background='black')
root.geometry('1920x1080')
def ok():
input = text1.get("1.0","end-1c")
gay = open('data.py', 'w')
gay.write(input)
gay.close()
os.startfile('data.py')
text1 = Text(root, bg="#6B6B6B", height=50, width=200)
text1.place(x=320, y=40)
but1 = Button(root, text="halleo", command=ok).pack()
root.mainloop()
答案 0 :(得分:0)
我认为这就是您的追求...很难从您的问题中分辨出来。我认为控制台是指文本区域。我取出了文件输出,但是可以放回去。
from tkinter import *
import subprocess
import shlex
def run_command(the_command):
process = subprocess.Popen(shlex.split(the_command), stdout=subprocess.PIPE)
output = process.stdout.read()
output = str(output).replace("b'", "").replace("\\n'", "")
lab1.configure(text=output)
def command():
the_input = text1.get("1.0", "end-1c")
run_command(the_input)
root = Tk()
root.configure(background='black')
root.geometry('1920x1080')
text1 = Text(root, bg="#6B6B6B", height=50, width=200)
text1.place(x=320, y=40)
but1 = Button(root, text="halleo", command=command).pack()
lab1 = Label(root, text="asdf", background='white')
lab1.pack()
root.mainloop()