R: [Tutor] snack classes

Andrea Valle marta_andrea at libero.it
Sun Nov 23 05:34:28 EST 2003


Hi Michael (and all), thanks and sorry:


This is a code sample

--------------
from Tkinter import *
from tkSnack import *
root=Tk()
initializeSnack(root)
# As required by Snack

from math import *

class Sig(Sound):

    def __init__(self):
        self.sec=2
        self.length=44100*self.sec


    def sine(self):
        l=self.length
        for x in range(l):
            y=int(10000*sin(float(x)*50))
            self.sample(x,y)
        return self

As you can see, I'd like to use the Sig class derived from the Sound class
to make some sample manipulation, i.e. the function sine create a sinusoidal
signal, etc.. The sample method of Sound is really powerful.
But:

>>>
s=Sig()
>>> s.sine()

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in ?
    s.sine()
  File "C:/Programmi/python 2.2.1/modello2.py", line 23, in sine
    self.sample(x,y)
  File "C:\PROGRA~1\PYTHON~1.1\tkSnack.py", line 288, in sample
    return _cast(self.tk.call((self.name, 'sample', index) + opts))
AttributeError: Sig instance has no attribute 'tk'
>>>

?
Thanks and best

-a-




More information about the Tutor mailing list