[Tutor] Program Critique
FxItAL@aol.com
FxItAL@aol.com
Wed, 20 Sep 2000 06:21:48 EDT
Hello,
I'm new to python and programming in general. I wrote the following as practice and beleive I should have used classes. Would someone critique this so I can learn from my mistakes?
Also, why doesn't the #win.title('Alarm') line work?
Sorry for the line idention my AOL doesn't allow the long lines. I've tried to make the format as clear as possible.
Thanks for your time and patience, Al
from Tkinter import *
from time import time, localtime, sleep
import thread
from winsound import *
root = Tk()
root.title('Reminder')
HourLabel = Label(root, text="Hour")
HourLabel.grid(row=0, column=1, padx=1, sticky=S)
MinLabel = Label(root, text="Minute")
MinLabel.grid(row=2, column=1, padx=1, sticky=N)
MessLabel = Label(root, text="Enter Message To Be Displayed On Alarm.")
MessLabel.grid(row=0, padx=10, pady=10, column=0)
UserEntryHour = IntVar()
HourEntry = Entry(root, state=NORMAL, textvariable=UserEntryHour, width=3)
HourEntry.grid(row=1, column=1, padx=1, sticky=N)
EntryHour = UserEntryHour.get()
UserEntryMin = IntVar()
MinEntry = Entry(root, state=NORMAL, textvariable=UserEntryMin, width=3)
MinEntry.grid(row=3, column=1, padx=1, sticky=N)
EntryMin = UserEntryMin.get()
MessEntry = StringVar()
EntryBox = Entry(root, state=NORMAL, textvariable=MessEntry, width=25)
EntryBox.grid(row=1, pady=1, padx=1, column=0)
MessInput = MessEntry.get()
Hour_Min=localtime(time())
ClockMin=Hour_Min[4]
ClockHour=Hour_Min[3]
InputMin=EntryMin
InputHour=EntryHour
def worker_thread():
global ClockMin, ClockHour, InputMin, InputHour, var
SetLabel = Label(root, text="Alarm Is Set!").grid(row=2)
EntryMin = UserEntryMin.get()
EntryHour = UserEntryHour.get()
Hour_Min=localtime(time())
ClockMin=Hour_Min[4]
ClockHour=Hour_Min[3]
InputMin=EntryMin
InputHour=EntryHour
if ClockHour<InputHour or ClockMin<InputMin:
while ClockHour<InputHour or ClockMin<InputMin:
sleep(5)
Hour_Min=localtime(time()) ClockMin=Hour_Min[4]
ClockHour=Hour_Min[3]
#print EntryMin
if ClockHour>=InputHour or ClockMin>=InputMin:
win = Tk()
#win.title('Alarm')
MessInput = MessEntry.get()
Message(win, text=MessInput, bg='royalblue', fg='ivory', width=500, relief=GROOVE).pack()
OkBut = Button(win, text='OK', command=win.destroy, width=10)
OkBut.pack()
display = win
PlaySound("c:\\windows\\media\\office97\\
reminder.wav",SND_FILENAME)
def ActionButCmd():
thread.start_new_thread(worker_thread, ())
def CancelButCmd():
SetLabel = Label(root, text=" ").grid(row=2)
UserEntryMin.set("0")
UserEntryHour.set("0")
CancelBut = Button(root, text='Cancel', command=CancelButCmd, width=10)
CancelBut.grid(row=4, padx=10, pady=10, sticky=E)
ActionBut = Button(root, text='Set Alarm', command=ActionButCmd, width=10)
ActionBut.grid(row=4, padx=10, pady=10, sticky=W)
QuitBut = Button(root, text='Quit', command=root.quit, width=10)
QuitBut.grid(row=4, padx=10, pady=10, column=1, sticky=E)
root.mainloop()