[Tutor] please help me with after method

Freedom Peacemaker guest0x013 at gmail.com
Wed Nov 16 13:48:01 EST 2016


Hi, i need help. I am using Python 3.4 and I have wrote little app for
windows only ( windows 7 and higher). Its timer and my app working but not
good. Some people said that i should use after method instead of update()
and nobody told me how. Ive tried many times but i dont know how do it
correctly. Please help me improve my app.

When you run app first enter minutes in entry then press start. If you
first press start your pc will shutdown with no time to stop it

my code:

from tkinter import *
import tkinter as tk
import time, os

def startCount():
    setTime = setMinutes.get() * 60
    strTime = str(setTime)
    timeSet = ("\""+"shutdown /s /f /t " +strTime+"\"")
    os.system(timeSet)
    for t in range(setTime, -1, -1):
        lcd = "{:02d}:{:02d}".format(*divmod(t, 60))
        timeString.set(lcd)
        try:
            root.update()
        except TclError:
            messagebox.showinfo('Info', 'Closing app wont stop timer.')
            return
        time.sleep(1)
    return

root = tk.Tk()
setMinutes = IntVar()
timeString = StringVar()
label_font = ('Verdana', 30)
root.geometry('210x120+200+200')
root.title('Timer v1.0')
root.resizable(0, 0)

L1 = tk.Label(root, text='How much time you have?')
L1.grid(row=0, columnspan=3, sticky='WE')

L2 = tk.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 = tk.Entry(root, textvariable=setMinutes).grid(row=2, column=1, padx=5,
pady=5)

B1 = tk.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)

root.mainloop()


More information about the Tutor mailing list