【发布时间】:2021-11-20 11:19:56
【问题描述】:
我正在研究 PySimpleGUI,我想在 PySimpleGUI 的窗口中显示图像。基本上,首先我将我的句子转换为字符,现在我想简单地在窗口中显示该字符的图像并说出哪个字符。 以下是我的代码:
from tkinter.constants import TRUE
import PySimpleGUI as sg
from PySimpleGUI.PySimpleGUI import Window
import pyttsx3
import time
import _thread
first_coloumn = [
[sg.LBox([], size=(20,10), key='-FILESLB-')],
[sg.Input(visible=False, enable_events=True, key='-IN-'), sg.FilesBrowse()],
[sg.Text('Enter what you wanna teach : ')],
[sg.Input(key='-inp-')],
[sg.Button('Reads'),sg.Button('Pause'),sg.Button('Slow'),sg.Button('Fast'),sg.Button('Stop'),sg.Button('Repeat'),sg.Button('Exit')]
]
image_viewer_coloumn = [
[sg.Text("Image Viewer")],
[sg.Image(key='-IMAGE-')],
]
layout = [
[
sg.Column(first_coloumn),
sg.VSeparator(),
sg.Column(image_viewer_coloumn),
]
]
window = sg.Window("Narrator",layout)
engine = pyttsx3.init()
words = []
chars = []
a = 0.5
stop = False
def splits(sentence):
return list(sentence)
def speak(a):
global stop
for i in range (len(chars)):
if stop:
break
elif chars[i]=='A' or chars[i]=='a':
filepath = "D:\Office-Work\Chars\A.png"
window['-IMAGE-'].update(filepath=filepath)
engine.say(chars[i])
time.sleep(a)
engine.runAndWait()
while TRUE:
event,values = window.read()
if event == 'Reads':
out = values['-inp-']
if out:
chars = splits(out)
stop = False
_thread.start_new_thread(speak, (a,))
我收到以下错误:
update() got an unexpected keyword argument 'filepath'
File "C:\Users\Kashi\OneDrive\Desktop\PySimpleGUI\a.py", line 45, in speak
window['-IMAGE-'].update(filepath=filepath)
【问题讨论】:
标签: python user-interface pysimplegui