0

I'm new to python coding with Raspberry Pi and using Tkinter (a GUI) and trying to create a script with a toggle button to close two other python processes. I used subprocesses as seen in the toggle button code but I do not know how to use subprocesses to kill processes from other scripts.

The code for my push button is


import tkinter as tk                 #brings in tkinter GUI for use
import subprocesses        

win = tk.Tk()                        # Creates the GUI window
win.geometry("300x300")              # Sets size for the GUI window

def close()                          # Close button function

  subprocess.Pclose(["python", 'tk1.py'])   # tk1.py is the other python file containing a process
  subprocess.Pclose(["python", 'tk2.py'])   # tk2.py is the other python file containing a process
  win.destroy()

STOPButton = tk.Button(win, text = 'STOP',command=close,bg='red',height=1, width =6)

STOPButton.place(relx=0.11, rely=0.19)

Once, I run the code, python does not recognize the "Pclose". I'm not sure what other solutions are out there to solve this problem. Any help would be appreciated.

I'm coding in python to create a python script to close two other python scripts. I've tried the command: subprocess. But there was no success. Would anyone know how to solve this problem?

And yes it is to KILL THE PROCESSES from the scripts by using another python script to control the kill process. And it is RASPIAN

  • What do you mean closing two other scripts? Do you mean killing running processes? – rolf82 Mar 01 '20 at 18:57
  • Are you using Raspbian or is it another OS ? – Jona Mar 01 '20 at 19:53
  • Hey there guys, yes KILL THE PROCESSES and it is RASPIAN – Karzoop Fair Mar 01 '20 at 20:49
  • "There was no success" is just as unhelpful as saying "did not work". *How* did it work or fail to? Did you simply not get any visible output? How do you *know* it didn't work? Did you inspect the returned Popen object? What did you find, when you performed that inspection? – Charles Duffy Mar 01 '20 at 21:04
  • Similarly, "tried the command: subprocess" doesn't tell us *how* you tried to use the subprocess module, so it gives us no way to identify a specific problem or otherwise tell you how to fix the way you used it. – Charles Duffy Mar 01 '20 at 21:05
  • Take a look at : https://stackoverflow.com/questions/15080500/how-can-i-send-a-signal-from-a-python-program – Jona Mar 01 '20 at 21:05
  • Jona so you're implying sending a signal through the python scripts. I didn't that was possible. Thanks I'll have a look. – Karzoop Fair Mar 01 '20 at 21:32
  • `subprocess.Pclose`? Where did you find documentation implying that that works at all? – Charles Duffy Mar 01 '20 at 21:53
  • I thought it would work since subprocess.Popen worked for someone for activating their code with their raspberry pi. I can't find the link right now to their code but if I do I'll try to post it. But do you have an alternative solution? – Karzoop Fair Mar 01 '20 at 21:53
  • Did any documentation tell you it would work? What the documentation *does* tell you can do is to store the object returned by `subprocess.Popen()`, and later use [`kill()`, `send_signal()`, or `terminate()` methods](https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal) on that stored object. – Charles Duffy Mar 01 '20 at 21:54
  • (that said, for all the harsh words, I've retracted my downvote and close vote, since you're now providing enough details that we can tell what's going wrong). – Charles Duffy Mar 01 '20 at 21:55
  • Alright, would you know an alternative method to stop the tk1.py and tk2.py files from running ? – Karzoop Fair Mar 01 '20 at 22:01
  • https://stackoverflow.com/questions/16866602/kill-a-running-subprocess-call – Charles Duffy Mar 01 '20 at 22:52
  • Mr. Charles Duffy to you also, thank you for the assistance. – Karzoop Fair Mar 02 '20 at 01:43

0 Answers0