interactive programe-pyTTS &Tk

R

Rob Williscroft

Nigel wrote in in comp.lang.python:
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.
 
N

Nigel

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.myContainer1 = Frame(parent)
self.myContainer1.pack()

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

self.button2 = Button(self.myContainer1)
self.button2.configure(text="Connor!") ### (2)
self.button2.configure(background="tan") ### (2)
self.button2.pack()


self.button3 = Button(self.myContainer1)
self.button3.configure(text="Nige", background="cyan") ### (3)
self.button3.pack()

self.button4 = Button(self.myContainer1, text="Carmel!", background="red")
### (4)
self.button4.pack()
def button1Click(self, event): ### (3)
tts = pyTTS.Create()
if self.button1:
self.button1["background"] = "yellow"
tts.Speak('Hello Molly.') ### (4)
else:
self.button1["background"] = "green"
root = Tk()
myapp = MyApp(root)
root.mainloop()
#"""<tt060.py
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top