<p>请尝试这段代码</p>
<pre><code>import tkinter as tk
def translate():
#==== Forget the position of the widgets in the window
for widget in ventana.winfo_children():
widget.pack_forget()
#=== Again place the entry box and the button
frase.pack(fill=tk.X,padx=5,pady=5,ipadx=5,ipady=5)
root.pack(padx=20,pady=10)
#==== Provide the text entered in the entry field
entrada="abcdefghilmnopqrstuvxyz"
salida="mnopqrstuvxyzabcdefghil"
letras=org_phrase.get().maketrans(entrada,salida)
#===print the translation (optional)
print(org_phrase.get().translate(letras))
#=== set it as label to display it
tk.Label(ventana,bg="white",text=org_phrase.get().translate(letras)).pack()
ventana=tk.Tk()
ventana.title("traductor")
ventana.geometry('200x300')
ventana.configure(background='white')
#=== Using stringvar to get the value
org_phrase=tk.StringVar()
#trans_phrase=tk.StringVar()
frase=tk.Entry(ventana,textvariable=org_phrase)
frase.pack(fill=tk.X,padx=5,pady=5,ipadx=5,ipady=5)
root =tk.Button(ventana,text="Traducir:",bg="black",fg="white",command=translate)
root.pack(padx=20,pady=10)
root.mainloop()
</code></pre>