[Tutor] Auto Refresh

Hi haztang17 at gmail.com
Sat Feb 28 22:41:14 CET 2009


Thank you for the reply, SetLabel is exactly what I am looking for. And yes,
you were correct, I just typoed the var_rate() when I was composing the
email. So what I did is in my main GUI class:

    wx.StaticText(self, -1, sampling rate':', (107, 150))
    self.rate_status = wx.StaticText(self, -1, '', (190, 150))    #just to
initialize rate_status to some location

    def refresh(self, event):
    x = rate()
    rate_text = self.rate_status.SetLabel(str(x.rate_var()))


and in my class that contains the variable (which will change every so often
at the end, so right now I'm modeling this with a random generator):

class rate():

    def rate_var(self):
    samp_rate = random.randint(44100, 48000)
    return samp_rate

I want to make it so once def refresh ran, it will continuously update and
display the new value in samp_rate in my main GUI at some time interval, say
every 10 seconds. I have looked up Timer, but I have not been able to make
it work. I looked up the documentation in Python's website to no avail. Can
anyone suggeste anything to help me?


On Fri, Feb 27, 2009 at 5:05 PM, <tutor-request at python.org> wrote:

>
> Message: 7
> Date: Sat, 28 Feb 2009 01:00:21 -0000
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] Auto Refresh
> To: tutor at python.org
> Message-ID: <goa2bk$kqn$1 at ger.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>        reply-type=original
>
>
> "Hi" <haztang17 at gmail.com> wrote
>
>
> > In my main GUI:
> >
> > def refresh(self, event):
> > x = refresh_var()
> > value = wx.StaticText(self, -1, str(x.var_rate))
>
> Its not clear how you are positioning Static Text, I suspect you
> need it as a opart of your main GUI and then reference it in
> here and use the SetLabel() method to update its contents.
>
> But I also not that you are not calling the var_rate method of x.
> Or does your code really look like
>
> value = wx.StaticText(self, -1, str(x.var_rate()))
>
> Notice the extra parens...
>
> > So each time I click on the button, which runs refresh, the new
> > value
> > generated by random.randint will be on top of the old number. Is
> > there any
> > commands I can use to remove the old value that is on the GUI window
> > before
> > I put the new one on there?
>
> I think you can just update the content of the original Text widget
> using SetLabel()
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> End of Tutor Digest, Vol 60, Issue 143
> **************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090228/c220cd4a/attachment.htm>


More information about the Tutor mailing list