【发布时间】:2022-01-16 01:07:35
【问题描述】:
我正在编写一个程序“翻译器”。写了一个编程接口。我想让它得到用户输入的内容,写入变量,翻译和输出。
但是我不明白该怎么做。我查看了很多论坛,但没有找到答案。 我希望用户在左侧文本输入窗口中输入要翻译的文本,我收到此文本,将其写入变量,翻译并在右侧窗口中显示翻译后的文本。我想这样做是为了使程序自动化,以便翻译是自动的,没有按钮。 `
from languages import lang
from function import *
from tkinter import *
from tkinter import ttk
import keyboard
from tkinter import messagebox
import googletrans
from googletrans import Translator
root = Tk()
app_width = 800
app_height = 500
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width / 2) - (app_width / 2)
y = (screen_height / 2) - (app_height / 2)
root.title('Переводчик')
root['bg'] = '#1D1B26'
root.geometry(f'{app_width}x{app_height}+{int(x)}+{int(y)}')
root.resizable(width=False, height=False)
style = ttk.Style()
style.configure('TCombobox', pady=15 )
language_selection1 = ttk.Combobox(root, values = lang, font="Comfortaa 10", )
language_selection1.current(1)
language_selection1.place(relx=0.16,y=50)
language_selection1.bind("<FocusIn>", defocus)
exchange_button = PhotoImage(file='transfer.png')
img_label = Label(image=exchange_button)
exchange_button = exchange_button.subsample(18,18)
exchange_button1 = Button(root, image=exchange_button,background='#2ee59d',borderwidth=0, command=exchange_button)
exchange_button1.place(relx=0.49,y=50)
language_selection2 = ttk.Combobox(root, values = lang, font="Comfortaa 10", )
language_selection2.set("Выберите язык")
language_selection2.place(relx=0.66,y=50)
language_selection2.bind("<FocusIn>", defocus)
first_frame = Frame(root, bg="Black")
first_frame.place(x=41, y=100,width= 250, height=200) #127
text1 = Text(first_frame, bg = "White")
text1.place(x=0,y=0,width= 250, height=200)
label2 = Label(root)
second_frame = Frame(root, bg="Black")
second_frame.place(x=528, y=100,width= 250, height=200) #441
text2 = Text(second_frame, bg = "White")
text2.place(x=0,y=0,width= 250, height=200)
root.mainloop()
/函数
def defocus(event):
event.widget.master.focus_set()
def exchange_button():
pass
/语言
lang = ['Belarusian',
'English',
'German',
'Italian',
'Japanese',
'Kazakh',
'Kyrgyz',
'Norwegian',
'Polish',
'Russian',
'Spanish',
'Swedish',
'Turkish',
'Ukrainian', ]
`
【问题讨论】:
-
您不知道如何将
input输入Python 程序? -
如果没有看到您的代码,我们将无法帮助您。
-
我添加了一些代码并更准确地描述了问题