Нужна помощь с кодом. Такой замысел: дабы не засорять программу, я хочу сделать 1 кнопку на основном окне (переводчик), которая открывает другое окно уже с голосовым выводом.
Вот код:
from tkinter import *
from tkinter import ttk
from googletrans import Translator
from tkinter import filedialog as fd
from tkinter import colorchooser
import pyttsx3
from tkinter import *
from gtts import gTTS
import os
root = Tk()
frame1 = Frame(root,
bg = “lightPink”,
height = “150”)
frame1.pack(fill = X)
frame2 = Frame(root,
bg = “lightgreen”,
height = “750”)
frame2.pack(fill=X)
label = Label(frame1, text = “Голосовой конвертор”,
font = “bold, 30”,
bg = “lightpink”)
label.place(x = 180, y = 70)
entry = Entry(frame2, width = 45,
bd = 4, font = 14)
entry.place(x = 130, y = 52)
entry.insert(0, “”)
def play():
language = “ru”
myobj = gTTS(text = entry.get(),
lang = language,
slow = False)
myobj.save(“convert.wav”)
os.system(“convert.wav”)
btn = Button(frame2, text = “ЖМИ!”,
width = “15”, pady = 10,
font = “bold, 15”,
command = play, bg='yellow')
btn.place(x = 250,
y = 130)
root.title(“Голосовой ассистент”)
root.geometry(“650x550+350+200”)
def click():
color = colorchooser.askcolor()
print(color)
colorHex = color
print(colorHex)
root.config(bg=colorHex)
button = Button(root, width=10, text='Изменить цвет', command=click)
def click():
color = colorchooser.askcolor()
print(color)
colorHex = color
print(colorHex)
window.config(bg=colorHex)
window = Tk()
window.geometry(“400x400”)
button = Button(window, width=15, text='Изменить цвет', command=click)
window.resizable(width = False, height = False)
window.title(“Window title”)
def open_file():
fd.askopenfilename()
def save_file():
fd.asksaveasfilename()
mainmenu = Menu(window)
window.config(menu = mainmenu)
filemenu = Menu(mainmenu, tearoff =0)
filemenu.add_command(label = “Open file”, command = open_file)
filemenu.add_command(label = “Save file”, command = save_file)
mainmenu.add_cascade(label = “File”, menu = filemenu)
mainmenu.add_cascade(label = “Settings”)
colors =
def tran():
text = t.get('1.0', END)
a = translator.translate(text, dest=languages.get())
t1.delete('1.0', END)
t1.insert('1.0', a.text)
window.geometry('500x350')
window.title('Переводчик')
window.resizable(width=False, height=False)
window =
translator = Translator()
label = Label(window, fg='black', bg='white', font='Arial 15 bold', text='Введите текст')
label.place(relx=0.5, y=35, anchor=CENTER)
t = Text(window, width=35, height=5, font='Arial 12 bold')
t.place(relx=0.5, y=100, anchor=CENTER)
languages = ttk.Combobox(window)
languages =
languages.place(relx=0.5, y=200, anchor=CENTER)
languages.current(1)
btn = Button(window, width=45, text='Перевести' , command=tran)
btn.place(relx=0.5, y=180, anchor=CENTER)
t1 = Text(window, width=35, height=5, font='Arial 12 bold')
t1.place(relx=0.5, y=260, anchor=CENTER)
entry = Entry(frame2, width = 45,
bd = 4, font = 14)
entry.place(x = 130, y = 52)
entry.insert(0, “”)
import tkinter as tk
def createNewWindow():
newWindow = tk.Toplevel(app)
labelExample = tk.Label(newWindow, text = “Новое окно”)
labelExample.pack()
app = tk.Tk()
buttonExample = tk.Button(app,
text=“Создать новое окно”,
command=createNewWindow)
buttonExample.pack()
app.mainloop()
button.pack()
window.mainloop()
# start the gui
root.mainloop()