'Tkinter Python Execution Issue
I am trying to execute code using tkinter GUI. I am not able to execute output. However, When I try only subprocess method it works fine. Can you please let me know what is wrong here.
from tkinter import *
import subprocess
main_window = Tk()
Label(main_window, text="Name of Test").grid(row =0,column=0)
test = Entry(main_window, width=50, borderwidth=5).grid(row=0,column=1)
Def on_click():
If test == "abc": subprocess.run(['python',r'C:\User\abc.py'], stdout=subprocess.PIPE)
Button(main_window, text='Run', command = on_click).grid(row=2, column=1)
main_window.mainloop()
Also, how to exit GUI window once process is complete?
Thanks
Solution 1:[1]
My guessing on what you were trying to achieve
from tkinter import *
import subprocess
main_window = Tk()
Label(main_window, text="Name of Test").grid(row=0, column=0)
entry = Entry(main_window, width=50, borderwidth=5)
entry.grid(row=0, column=1)
def on_click():
entry_text_content = entry.get()
if entry_text_content == "abc":
subprocess.run(
['python',r'C:\User\abc.py'],
stdout=subprocess.PIPE,
)
Button(main_window, text='Run', command = on_click).grid(row=2, column=1)
main_window.mainloop()
Please pay attention to the comparison of the input: I'm not comparing entry
with "abc"
, but I'm calling entry.get()
at first to retrieve text from the entry, and then compare this text with "abc"
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |