[Tutor] after(), how do I use it?
michael scott
jigenbakuda at yahoo.com
Tue Apr 26 03:34:00 CEST 2011
Now I understand what I misunderstood. Well he imported Tkinter as tk, so I
thought if it belonged to Tkinter it would be tk.after(), but the after was
attached to the app, so it was in actuality app.after() . app inherits from the
tk class (taking with it all its methods), so its a built in function of
tkinter.
I read the whole thread of the first google response, but I still wasn't sure if
it was a Tkinter function or a python function. I searched the actual python
documentation quite extensively, but briefly glanced at the tkinter effbot page,
after not seeing it I came here. I was just looking for the documentation on
after().
But yea, this is what I needed
id = w.after(time, callback)
So I know it takes 2 arguments, and I know to use it recursively in my problem,
so now I understand enough about this function to put it to good use :) Thank
you.
----
What is it about you... that intrigues me so?
________________________________
From: Wayne Werner <waynejwerner at gmail.com>
To: michael scott <jigenbakuda at yahoo.com>
Cc: tutor at python.org
Sent: Mon, April 25, 2011 9:15:10 PM
Subject: Re: [Tutor] after(), how do I use it?
On Mon, Apr 25, 2011 at 8:02 PM, michael scott <jigenbakuda at yahoo.com> wrote:
Here is the code in its entirety, it works although I don't see after() defined,
so I assumed it was a built in function. I can just copy and paste parts of this
code into my project, so its not imperative that I understand, but I prefer to
use the weapons I've been given. So I hope that you guys can understand it a bit
better after I post this.
>
That it is indeed. Do you understand classes and subclassing in Python? App is a
subclass of tk.Tk. If you have done any of your own programming in Tkinter, you
should know that Tk is the "main" class in Tkinter. If you do a Google search
for "Tkinter after", the top two results will answer your question:
http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=tkinter+after
HTH,
Wayne
>import Tkinter as tk
>
>class App(tk.Tk):
> def __init__(self,*args, **kwargs):
> tk.Tk.__init__(self, *args, **kwargs)
> self.label = tk.Label(self, text="", width=20, anchor="w")
> self.label.pack(side="top",fill="both",expand=True)
> self.print_label_slowly("Hello, world!")
>
>
> def print_label_slowly(self, message):
> '''Print a label one character at a time using the event loop'''
> t = self.label.cget("text")
> t += message[0]
> self.label.config(text=t)
> if len(message) > 1:
> self.after(500, self.print_label_slowly, message[1:])
>
>app = App()
>app.mainloop()
>
>
>
> ----
>What is it about you... that intrigues me so?
>
>
>
>
>
________________________________
From: Adam Bark <adam.jtm30 at gmail.com>
>To: tutor at python.org
>Sent: Mon, April 25, 2011 8:50:16 PM
>Subject: Re: [Tutor] after(), how do I use it?
>
>
>On 26/04/11 01:36, michael scott wrote:
>> Hello, I asked for help in another location and it solved my problem, but the
>>only problem is I don't fully understand the after function. Here is part of the
>>code that was given to me.
>>
>>
>> def print_label_slowly(self, message):
>> '''Print a label one character at a time using the event loop'''
>> t = self.label.cget("text")
>> t += message[0]
>> self.label.config(text=t)
>> if len(message) > 1:
>> self.after(500, self.print_label_slowly, message[1:])
>>
>> I understand it, and the gist of how it works, but the self.after... I can not
>>find any documentation on it (because after is such a common word), so can you
>>guys tell me how it works. Is this a built in function (didn't see it on the
>>built in function list)? Does it always take 3 arguements? Is this a user made
>>function and I'm just overlooking where it was defined at?
>
>The function you have shown there appears to be a class method. self.after means
>you are calling another method of the same function that print_label_slowly is a
>part of.
>Do you have the rest of the code? If you're still confused post it and hopefully
>we can clear it up for you.
>
>HTH,
>Adam.
>_______________________________________________
>Tutor maillist - Tutor at python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110425/b964f3dd/attachment-0001.html>
More information about the Tutor
mailing list