Python Forum
Start stop button stack
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Start stop button stack
#1
Hello help me iam new in the world of tkinter and programming
I want in same window two button one start and one stop . If you push start call any python script and run in background file
And the stop if push button stoppind the threading running script from start button .. sorry forvmy English

from tkinter import *
import os
from threading import *

def Start()
	t1=Thread(target=Run)
	t1.start()
def Run():
	os.system("python3 masterscript.py") # or something else py script 
def stop():
	# i want to stop masterscript run def Run()
root = Tk()
root.title("test")
root.geometry("500x500")

app = Frame(root)
app.grid()

startBut = Button(app, text="Start", command=Start)
stopBut = Button(app, text="stop", command=stop)

startBut.grid()
stopBut.grid()

root.mainloop()
Reply
#2
Help me please
Reply
#3
I think you want to use subprocess instead of threads.

https://docs.python.org/3/library/subprocess.html
Reply
#4
But how ? Iam junior class in python . Any example in my code ?
Reply
#5
Search for python subprocess or python subprocess library. There are blog posts and tutorials and examples.

I would ignore the GUI to begin with and focus on launching your script as a subprocess. Once you can do that, add 'input('Press Enter to stop process')' and the code to terminate the subprocess. Once you know how to launch and terminate the subprocess it will be simple to connect that code up to some buttons in a GUI,
Reply
#6
Ok I made it .many thanks Wink
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] start and stop websocket-client using button GUI zinho 5 2,375 Dec-27-2022, 06:06 PM
Last Post: deanhystad
  Progressbar with start and stop jelo34 3 4,877 Nov-30-2020, 03:36 AM
Last Post: deanhystad
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,951 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Stop Watch star/stop problem macellan85 1 2,524 Jun-12-2019, 06:04 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020