<DIV>
<DIV><FONT face=Arial size=2>Hi all! </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I was wondering if anyone could help me out. </FONT></DIV>
<DIV><FONT face=Arial size=2>I wrote a little alarm clock program in Python, and now want to incorporate it into a Tkinter frame. It's all going quite well, but this is my first experience with Tk and I've hit a bit of a wall. One of the button's commands refers to a method (called 'act') which has a while loop within it (keeps track of the time and <EM>ought to</EM> display it in the Tk frame). But the problem is the while loop is interupting the root mainloop, so the labels will not update, and freezes until the while loop is over. </FONT></DIV>
<DIV><FONT face=Arial size=2>Does anyone have any suggestions to get round this?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Here's the program:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>import time, winsound<BR>from Tkinter import *</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>class App:<BR> def __init__(self,master):<BR> self.master = master<BR> frame = Frame(master,bd=6,relief=RIDGE)<BR> frame.pack()<BR> frame2 = Frame(master)<BR> frame2.pack()</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> self.list = ["9","8","7","6","5","4","3","2","1","0"]<BR> self.stringv = StringVar()<BR> self.stringv.set("0")<BR> self.stringv2 = StringVar()<BR> self.stringv2.set("0")<BR> self.stringv3 = StringVar()<BR> self.stringv3.set("0")<BR> self.stringv4 = StringVar()<BR> self.stringv4.set("0")</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> self.lab1 = Label(frame,font=("helvica",22),bg="red",<BR> textvariable=self.stringv).pack(side=LEFT)<BR> self.b1 = Button(frame2,text="H",width=3,command=self.change)<BR> self.b1.pack(side=LEFT)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> self.lab2 = Label(frame,font=("helvica",22),bg="red",<BR> textvariable=self.stringv2).pack(side=LEFT)<BR> self.b2 = Button(frame2,text="h",width=3,command=self.change2)<BR> self.b2.pack(side=LEFT)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> self.lab3 = Label(frame,text=":",font=("helvica",22),<BR> bg="red",).pack(side=LEFT)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> self.lab4 = Label(frame,font=("helvica",22),bg="red",<BR> textvariable=self.stringv3).pack(side=LEFT)<BR> self.b3 = Button(frame2,text="M",width=3,command=self.change3)<BR> self.b3.pack(side=LEFT)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> self.lab5 = Label(frame,font=("helvica",22),bg="red",<BR> textvariable=self.stringv4).pack(side=LEFT)<BR> self.b4 = Button(frame2,text="m",width=3,command=self.change4)<BR> self.b4.pack(side=LEFT)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> self.set_button = Button(master,text="Set",width=20,<BR> command=self.act).pack()<BR> <BR> def change(self):<BR> if int(self.stringv2.get()) < 3:<BR> self.list1 = self.list[7:]<BR> i = self.list1.index(self.stringv.get())<BR> self.stringv.set(self.list1[i-1])<BR> else:<BR> self.list1 =
self.list[8:]<BR> i = self.list1.index(self.stringv.get())<BR> self.stringv.set(self.list1[i-1])</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> def change2(self):<BR> self.list2 = self.list[6:]<BR> if self.stringv.get() == "2":<BR> i = self.list2.index(self.stringv2.get())<BR> self.stringv2.set(self.list2[i-1])<BR> else: <BR> i = self.list.index(self.stringv2.get())<BR> self.stringv2.set(self.list[i-1])</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> def change3(self):<BR> self.list3 = self.list[4:]<BR> i = self.list3.index(self.stringv3.get())<BR> self.stringv3.set(self.list3[i-1])</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> def change4(self):<BR> i = self.list.index(self.stringv4.get())<BR> self.stringv4.set(self.list[i-1])</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> def act(self):<BR> self.ring = self.stringv.get()+self.stringv2.get()+":"\<BR> +self.stringv3.get()+self.stringv4.get()<BR> self.track = [None]<BR> self.c = self.clock()<BR> self.stringv.set(self.c[0])<BR> self.stringv2.set(self.c[1])<BR> self.stringv3.set(self.c[3])<BR> self.stringv4.set(self.c[4])</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> while 1:<BR> self.c = self.clock() <BR> if self.c != self.ring:<BR> if self.c == self.track[-1]: pass<BR> else:<BR> self.stringv.set(self.c[0])<BR> self.stringv2.set(self.c[1])<BR>
self.stringv3.set(self.c[3])<BR> self.stringv4.set(self.c[4])<BR> self.track.append(self.c)<BR> else: winsound.PlaySound("rooster.wav", winsound.SND_LOOP)<BR> <BR> def clock(self):<BR> t1 = time.localtime()[3:5]<BR> if t1[0] in range(10): tm1 = '0'+ str(t1[0])<BR> else: tm1 = str(t1[0])</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> if t1[1] in range(10): tm2 = '0'+ str(t1[1])<BR> else: tm2 = str(t1[1])</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> tm3 = tm1 + ":" + tm2<BR> return tm3</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>if __name__ == "__main__":<BR> root=Tk()<BR> root.title("")<BR> root.geometry("100x97+300+200")<BR> App(root)<BR> root.mainloop()<BR></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thanks in advance.</FONT></DIV></DIV><p>Send instant messages to your online friends http://uk.messenger.yahoo.com