Guest User

Untitled

a guest
Jun 28th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. from tkinter import *
  2. from googletrans import Translator
  3. root = Tk()
  4. root.title("Translator GUI")
  5. root.geometry("300x300")
  6. def reset():
  7.     global root
  8.     root.destroy()
  9.     root = Tk()
  10.     root.title("Translator GUI")
  11.     root.geometry("300x300")
  12.     lab = Label(root,text="Enter the text you would like to translate ?")
  13.     lab.grid(row=0, column=2)
  14.     tren = Entry(root, width=50)
  15.     tren.grid(row=1, column=2)
  16.     but = Button(root, text="Translate!", command= lambda : gtrans(tren.get()))
  17.     but.grid(row=2, column=2, padx=5, pady=5)
  18.     but2 = Button(root, text="Clear", command = lambda: reset())
  19.     but2.grid(row=2, column=3, padx=5, pady=5)
  20.     root.mainloop()
  21. def gtrans(text1):
  22.     global root
  23.     translator = Translator()
  24.     result = translator.translate(text1)
  25.     restext = result.text
  26.     lab2 = Label(root, text="Translated Text:")
  27.     lab2.grid(row=3, column=2)
  28.     lab3 = Label(root, text=restext.strip())
  29.     lab3.grid(row=4, column=2)
  30.  
  31.    
  32. lab = Label(root,text="Enter the text you would like to translate ?")
  33. lab.grid(row=0, column=2)
  34. tren = Entry(root, width=50)
  35. tren.grid(row=1, column=2)
  36. but = Button(root, text="Translate!", command= lambda : gtrans(tren.get()))
  37. but.grid(row=2, column=2, padx=5, pady=5)
  38. but2 = Button(root, text="Clear", command = lambda: reset())
  39. but2.grid(row=2, column=3, padx=5, pady=5)
  40. root.mainloop()
Add Comment
Please, Sign In to add comment