I have seen similar answers even on stackoverflow but i cant solve my problem. This is my first program doing something specific. Its for Windows users only (windows 7 and higher). When you launch it in first Entry input minutes and press START button. This starts counting. Second Entry is for password. When typed 'dark' and STOP pressed it stops shutdown. And when im closing application with X button it gives me this:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1482, in __call__
return self.func(*args)
File "C:\MyWorld\newIdea.py", line 26, in startCount
root.update()
File "C:\Python34\lib\tkinter\__init__.py", line 965, in update
self.tk.call('update')
_tkinter.TclError: can't invoke "update" command: application has been destroyed
Can you help me handle this exception? Or maybe edit my code to avoid this error?
import sys, time, os
from tkinter import *
import tkinter as tk
def change_1():
B1['state'] = tk.DISABLED
B2['state'] = tk.NORMAL
def change_2():
B1['state'] = tk.NORMAL
B2['state'] = tk.DISABLED
def change_3():
B1['state'] = tk.DISABLED
B2['state'] = tk.DISABLED
def startCount():
setTime = setMinutes.get() * 60
strTime = str(setTime)
timeSet = ("\""+"shutdown /s /f /t " +strTime+"\"")
os.system(timeSet)
change_1()
for t in range(setTime, -1, -1):
lcd = "{:02d}:{:02d}".format(*divmod(t, 60))
timeString.set(lcd)
root.update()
time.sleep(1)
return
def stopCount():
passwd = "dark"
passwdGet = getPass.get()
if passwd != passwdGet:
messagebox.showinfo('Wrong', 'Its not correct password')
change_3()
else:
messagebox.showinfo('Good', 'Turn off canceled')
os.system("shutdown /a")
change_2()
return
root = tk.Tk()
setMinutes = IntVar()
getPass = StringVar()
timeString = StringVar()
label_font = ('Verdana', 30)
root.geometry('260x150+200+200')
root.title('Timer v1.4')
root.resizable(0, 0)
L1 = Label(root, text='How much time You have?').grid(row=0, column=1)
L2 = Label(root, textvariable=timeString, font=label_font, bg='white',
fg='orange', relief='raised', bd=3)
L2.grid(row=1, columnspan=3, sticky='WE', padx=5, pady=5)
E1 = Entry(root, textvariable=setMinutes).grid(row=2, column=1, padx=5, pady=5)
B1 = Button(root, text='S T A R T', fg='green', bg='black', command=startCount)
B1.grid(row=2, rowspan=2, sticky='NS', column=0, padx=5, pady=5)
E2 = Entry(root, textvariable=getPass).grid(row=3, column=1, padx=5, pady=5)
B2 = Button(root, text='S T O P', fg='red', bg='black', command=stopCount,
state=tk.DISABLED)
B2.grid(row=2, rowspan=2, sticky='NS', column=2, padx=5, pady=5)
root.mainloop()