-5

This is my first question. I have a python program that recognize voice and reply with voice.

I wish to add a little GUI for my program (it should have only an image on background and a button to quit the program)

I would like that when I launch my code from terminal, it opened a Tkinter window and at the same time the python program start.

I’m working on Mac Os.

I use speech_recognition package to recognize voice and I use NSS speaker to let my computer speak.

This is a example of my code:

import speech_recognition as sr
from  AppKit import NSSpeechSynthesizer
#VARIABLES
L = sr.Recognizer() #LISTENING
nssp = NSSpeechSynthesizer #SPEAKING
S = nssp.alloc().init()
while True:
    audio = L.listen(source) 
    s = L.recognize_google(audio, language="en-US")
    if s == "hi":
        S.startSpeakingString_("Hello!!!")

Where do I have to write the Tkinter instructions to make sure that when I run my code it opens only a Tkinter window (while my program goes on) and not a shell's one?

  • 2
    Welcome to StackOverflow! Please read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and [how to give a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This will make it much easier for others to help you. – Aditi Apr 18 '18 at 07:58

1 Answers1

0

You'll find it difficult to introduce your GUI as your code has already been written, note that everything in Tkinter has to be stored in some sort of Label or Widget and so you can't just print what you already have onto the Tkinter screen.

Here is some code to create a basic Tkinter window. Try searching online and playing around with how to present your variables within said window

import tkinter
from tkinter import *

root = tkinter.Tk()
root.configure(background = "#66ffdd") #here you can use any hex color code or just leave it blank and configure as default
root.title("Voice Program") #use the name of your program (this is the window header/title)
root.geometry("800x500") #these are your window dimensions

welcome = tkinter.Message(root, text = "Welcome to my program")
button = tkinter.Button(root, text="This button", command=print("hello")) #here insert a function for the button to perform i.e quit

welcome.pack()
button.pack() #packing presents your variables to the window - you can also use other geometry managers like grid

This site is really useful for showing you what widgets are available and what you can do with them - try searching any issues or posting a more specific question in the future if you struggle.

http://effbot.org/tkinterbook/button.htm