我想制作一个用文本框拉出gui的程序。你会说些什么,它会给文本框赋值,它会自动更新。
到目前为止,我的代码只允许您说出一些内容,然后会弹出:
import wx
class MyFrame(wx.Frame):
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None,
pos=wx.DefaultPosition, size=wx.Size(450, 100),
style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU |
wx.CAPTION | wx.CLOSE_BOX |wx.CLIP_CHILDREN,
title="PyDa")
panel = wx.Panel(self)
my_sizer = wx.BoxSizer(wx.VERTICAL)
lbl = wx.StaticText(panel,
label="Hello I am Pyda the Python Digital Assistant. How can I help you?")
my_sizer.Add(lbl, 0, wx.ALL, 5)
favicon = wx.Icon('Pyda.ico', wx.BITMAP_TYPE_ICO, 16, 16)
wx.Frame.SetIcon(self, favicon)
self.txt = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER,size=(400,30))
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
try:
self.txt.Value = r.recognize(audio)
except LookupError:
print("Could not understand audio")
self.txt.SetFocus()
self.txt.Bind(wx.EVT_TEXT_ENTER, self.OnEnter)
my_sizer.Add(self.txt, 0, wx.ALL, 5)
panel.SetSizer(my_sizer)
self.Show()
如果缩进不正确,我很抱歉,我尝试使用堆栈溢出编辑器
基本上我希望txtCTRL框能够自动更新用户所说的内容而不是从程序开头获取它。
谢谢!