I am creating a UI for another python program and it essentially just makes an interactive component to the project. The goal is to have a specific label that updates (print statements) from the python program the button runs. This is what I have programmed in my UI...
import tkinter as ttk
import subprocess
import sys
import time
import os
import tkinter.font as font
from tkinter.ttk import *
app = ttk.Tk()
app.geometry("400x400")
app.configure(bg='gray')
photo = ttk.PhotoImage(file=r"C:\Users\ex\ex_button_active.png")
myFont = font.Font(family='Helvetica', size=20, weight='normal')
ttk.Label(app, text='Ex', bg='gray', font=(
'Verdana', 15)).pack(side=ttk.TOP, pady=10)
app.iconbitmap(r'C:\Users\ex\ex_icon.ico')
def ex_activation():
global pro
print("Running program!")
pro = subprocess.Popen("python programex.py", shell=True)
def ex_stop():
global pro
print("Stopping Program... Please Wait!")
os.kill(pro.pid, 0)
ex_activation_button = ttk.Button(app, bg='black', image=photo, width=120, height=120, command=ex_activation)
ex_stop_button = ttk.Button(app, bg='Gray', text='Stop Program', width=12, command=ex_stop, height=3)
ex_stop_button['font'] = myFont
app.title("Ex")
ex_activation_button.pack(side=ttk.TOP)
ex_stop_button.pack(side=ttk.LEFT)
# app.mainloop()
while True:
try:
app.update()
app.update_idletasks()
except KeyboardInterrupt:
pass
If anyone has an idea of how I can implement This StackOverflow Post into my code, I would greatly appreciate the help and support.
EDIT for acw1668 These are some tests I had run and got some strange numbers in the Pycharm run window instead of the UI.
Running program!
3528
Stopping Program 3528 ... Please Wait!
monitor done
Running program!
144
Stopping Program 144 ... Please Wait!
monitor done
Running program!
14008
Stopping Program 14008 ... Please Wait!
monitor done
Running program!
21748
Stopping Program 21748 ... Please Wait!
monitor done