Home > Mobile >  Python tkinter button showing script to scrolledtext box
Python tkinter button showing script to scrolledtext box

Time:10-06

When i press the start button, it runs the other script but only shows it in the other terminal, not in the GUI scrolledtext box i have. is there a simple fix for my problem? not finding an answer anywhere.

from tkinter import *
from tkinter import ttk
from tkinter import filedialog
import sys
import os
import tkinter.scrolledtext as tkst

root = Tk()
root.title("WLP")
root.geometry("950x450")
root.iconbitmap("Vo1d.ico")
root.configure(bg='#0c0c0c')

def clickstart():
  os.system('python WLP.py')

Button1 = Button(root, text="START", bg="#0c0c0c", fg="#C0C0C0", command=clickstart)  #)
Textbox = tkst.ScrolledText(root, width=75, height=10, bg="#0c0c0c", fg="#C0C0C0")
Button1.grid(row=10, column=5, pady=15)
Textbox.grid(row=17, column=5)

root.mainloop()

CodePudding user response:

This is far from a good way to do it, but this should work (after importing subprocess)

def clickstart():
    output = subprocess.run(['python', 'WPL.py'], stdout=subprocess.PIPE, check=True)
    output = str(output.stdout, encoding='utf-8')
    Textbox.insert(1.0, output)
  • Related