I'm trying to make an aplication for my Raspberry Pi. An intervalometer for photographic purposes. I have made a GUI with tkinter but I can't found the way to cancel a running script , because all the buttons are blocked when the script is running. May be it's no possible because my scripts contains loops ( for i in range()... I have been trying the ".after" method but this one just stop the script without cancelling it. Thanks in advence for your help
Asked
Active
Viewed 1,103 times
0
-
Welcome to SO. Please read how to ask; you should provide a minimal complete verifiable example of your script – Foon Feb 16 '17 at 14:46
-
You've asked this same question on the Raspberry Pi forums. https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=174563&p=1114532#p1114532 If you add your code on the forums inside [code][/code] tags I can help you. – scotty3785 Feb 16 '17 at 15:31
-
I'm very beginner and I don't know exactly how to insert code... Thanks – josepraspi Feb 17 '17 at 15:31
-
I start to see the light.... This is the situation now, not the best , but I can stop and reset the START script: – josepraspi Feb 17 '17 at 15:34
-
Sorry I want to add CODE to this question but I don't know how to do it – josepraspi Feb 17 '17 at 15:44
2 Answers
2
You can try to use threading or multiprocess. You can refer to this post to find out more about it. Also, if you just want to stop the script from running, you can either send SIGKILL signal to your program from Terminal (the command is killall Python -9
) or add a button in your program that calls sys.exit()
-
@josepraspi You can choose to accept the answers that you found helpful. Just click on the check symbol (✓) on the left side of each answer. – Mia Feb 18 '17 at 03:44
0
from Tkinter import *
class Example:
def __init__(self, master):
self.etfilm = Label(root,width=12, font=('arial narrow', 14, 'normal'),fg="white", bg="green")
self.etfilm.grid(row=0, column=0,columnspan=1, padx=3, pady=2, sticky=NSEW)
self.etstatus = Label(root,width=12, font=('arial narrow', 14, 'normal'),bg="yellow")
self.etstatus.grid(row=0, column=1,columnspan=1, padx=3, pady=2, sticky=NSEW)
self.textBox = Text(root,height= 1,width=2, relief=SUNKEN, font=('arial', 18, 'normal'),)
self.textBox.grid(row=0, column=2, ipadx=13, padx=0, sticky=NSEW)
self.botshoot = Button(root, width=18, font=('arial narrow', 30, 'normal'), text="START ", activebackground="#00dfdf")
self.botshoot.grid(row=4, rowspan=2, column=0,columnspan=3,ipady=15,pady=1, sticky=NSEW)
self.botshoot.configure(command=self.start)
self.botkam = Button(root,width=10, font=('arial', 24, 'normal'), text="VIDEO SETTINGS", activebackground="#00dfdf")
self.botkam.grid(row=6, rowspan=3, column=0,columnspan=2, pady=1, sticky=NSEW)
self.botkamStop = Button(root,width=3, font=('arial', 24, 'normal'), text="STOP", activebackground="#00dfdf")
self.botkamStop.grid(row=6, rowspan=3, column=2, pady=1, sticky=NSEW)
self.botSelf = Button(root,width=10, font=('arial', 24, 'normal'), text="ACTIVATE SELFTIMER", activebackground="#00dfdf")
self.botSelf.grid(row=9, rowspan=3, column=0,columnspan=2, pady=1, sticky=NSEW)
self.botSelf1 = Button(root,width=3, font=('arial', 24, 'normal'), text="STOP", activebackground="#00dfdf")
self.botSelf1.grid(row=9, rowspan=3, column=2, pady=1, sticky=NSEW)
self.botConf = Button(root,heigh=2, font=('arial', 18, 'normal'), text="CONFIGURE", activebackground="red")
self.botConf.grid(row=12, rowspan=3, column=0,columnspan=1, pady=1, sticky=NSEW)
self.botStop = Button(root,heigh=2, font=('arial', 18, 'normal'), text="STOP/RESET", activebackground="red")
self.botStop.grid(row=12, rowspan=3, column=1,columnspan=2, pady=1, sticky=NSEW)
self.botStop.configure(state=DISABLED,command=self.stop)
def start(self):
self.count = 0
self.cancel_id = None
self.botConf.configure(state=DISABLED)
self.botshoot.configure(state=DISABLED)
self.botStop.configure(state=NORMAL)
self.counter()
def counter(self):
self.textBox.delete("1.0", END)
if self.count < 10:
self.count += 1
self.textBox.insert(END, str(self.count)+'\n\n')
self.cancel_id = self.textBox.after(1000, self.counter)
root.update_idletasks()
print(self.count)
def stop(self):
if self.cancel_id is not None:
self.textBox.after_cancel(self.cancel_id)
self.cancel_id = None
self.textBox.insert(END, 0)
self.textBox.delete("1.0", END)
self.botConf.configure(state=NORMAL)
self.botshoot.configure(state=NORMAL)
root=Tk() Example(root) root.mainloop()

josepraspi
- 13
- 5