interactive programe-pyTTS &Tk

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nigel

    #1

    interactive programe-pyTTS &Tk

    from Tkinter import *
    import pyTTS
    Hi i am trying to get a button so that when i click on it i hear a voice say
    "Hi Molly" this is my code so far.Can any one shed any light on this for
    please.
    Thanks Nige.

    class MyApp:
    def __init__(self, parent):
    self.myContaine r1 = Frame(parent)
    self.myContaine r1.pack()

    self.button1 = Button(self.myC ontainer1)
    self.button1 ["text"] = "Hi Molly!" ### (1)
    self.button1["background "] = "green" ### (1)
    tts = pyTTS.Create()
    tts.Speak ('hello molly')
    self.button1.pa ck()

    self.button2 = Button(self.myC ontainer1)
    self.button2.co nfigure(text="C onnor!") ### (2)
    self.button2.co nfigure(backgro und="tan") ### (2)
    self.button2.pa ck()


    self.button3 = Button(self.myC ontainer1)
    self.button3.co nfigure(text="N ige", background="cya n") ### (3)
    self.button3.pa ck()

    self.button4 = Button(self.myC ontainer1, text="Carmel!", background="red ")
    ### (4)
    self.button4.pa ck()
    def button1Click(se lf, event): ### (3)
    tts = pyTTS.Create()
    if self.button1:
    self.button1["background "] = "yellow"
    tts.Speak('Hell o Molly.') ### (4)
    else:
    self.button1["background "] = "green"
    root = Tk()
    myapp = MyApp(root)
    root.mainloop()
    #"""<tt060.p y


  • Rob Williscroft

    #2
    Re: interactive programe-pyTTS &amp;Tk

    Nigel wrote in news:mailman.53 4.1159111835.10 491.python-list@python.org
    in comp.lang.pytho n:
    from Tkinter import *
    import pyTTS
    Hi i am trying to get a button so that when i click on it i hear a
    voice say "Hi Molly" this is my code so far.Can any one shed any light
    on this for please.
    Thanks Nige.
    Your problem appears to be that you do not know how to associate
    an action (the press of the button) with the code you want to run
    ( tts.Speak ('hello molly') ).


    Tk buttions have a command attribute that is called when the button
    is clicked:

    self.button1[ 'command' ] = HelloMolly


    Where HelloMolly is an already defined python callable, for example:

    def HelloMolly():
    self.tts.Speak ('hello molly')

    The above defenition of HelloMolly requires that somtime before it
    is called, self.tts is created:

    self.tts = pyTTS.Create()

    HTH.

    Rob.
    --

    Comment

    Working...