+ 1

Friends I have an issue with this code in this code when I run the program the translation doesn't work

from tkinter import * from tkinter import ttk from googletrans import Translator, LANGUAGES #def change(text='type',src='en',dest='hi'): # text1 = text # src1 = src # dest1 = dest # trans = Translator() # trans1 = trans.translate(text,src=src1,dest=dest1) # return trans1.text # #return trans1 for more details def change(text='type', src='English', dest='Hindi'): try: trans = Translator() trans1 = trans.translate(text, src=src, dest=dest) return trans1.text except Exception as e: return str(e) def data(): s = comb_sor.get() d = comb_dest.get() masg = Sor_txt.get(1.0,END) textget = change(text=masg,src=s,dest=d) dest_txt.delete(1.0,END) dest_txt.insert(END,textget) root = Tk() root.title("Translater") root.geometry("400x600") root.config(bg="yellow") lab_txt = Label(root,text="Google",font=("Time New Roman",25,"bold"),bg="blue",fg="white", relief="solid",bd=7,padx=4,pady=4,anchor="center") lab_txt.place(x=112,y=50,height=125, width=480) frame = Frame(root).

18th Oct 2023, 1:42 PM
Codex
Codex - avatar
1 ответ
+ 1
You are importing ttk from tkinter, but you don't use it anywhere in your code. You can remove this line: ```python from tkinter import ttk ``` You have commented out the change function, and it's not defined anywhere in the code. You should uncomment the change function and define it correctly. Replace the change function definition with this code: ```python def change(text='type', src='en', dest='hi'): try: trans = Translator() trans1 = trans.translate(text, src=src, dest=dest) return trans1.text except Exception as e: return str(e) ``` You need to import the Translator class from the googletrans library. Add this import statement at the beginning of your code: ```python from googletrans import Translator ``` In the data function, you are trying to get the source and destination languages from comb_sor and comb_dest, but you haven't defined these widgets anywhere in your code. You should create comboboxes for source and destination languages and update the data function accordingly. It seems like you're creating a GUI application, but the code you've posted is incomplete. You need to create the necessary GUI components, such as labels, comboboxes, text widgets, and buttons, to make your translator application functional. You should also call the root.mainloop() function at the end of your script to start the GUI event loop. Here's a basic example of how you can create source and destination comboboxes and a text widget for input and output: ```python comb_sor = ttk.Combobox(root, values=list(LANGUAGES.keys())) comb_sor.place(x=20, y=200) comb_dest = ttk.Combobox(root, values=list(LANGUAGES.keys())) comb_dest.place(x=300, y=200) Sor_txt = Text(root, font=('arial', 10), wrap=WORD, width=20, height=10, padx=5, pady=5) Sor_txt.place(x=20, y=250) dest_txt = Text(root, font=('arial', 10), wrap=WORD, width=20, height=10, padx=5, pady=5) dest_txt.place(x=300, y=250) ```
23rd Oct 2023, 9:52 AM
Coderwe2
Coderwe2 - avatar