Python Forum
Tkinter | entry output. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Tkinter | entry output. (/thread-35042.html)



Tkinter | entry output. - Sap2ch - Sep-24-2021

Good night forum. Let me help in times of crisis. I write the key in the first line, but this key knocks out to me not in the second line, but in the terminal. How could you solve this problem? I hope for your understanding and patience. Thanks for the opportunity to get help from you. The backup copy of the script is at the bottom:

from tkinter import *
import tkinter as tk

root = Tk()

root.title('Переводчик')

fruit_r_to_e = {'яблоко':'apple', "ананас":'pineapple'}
fruit_e_to_r = {"apple": "яблоко", "pineapple": "ананас"}

mystring = tk.StringVar()
mystring1 = tk.StringVar()    

def getvalue():
    global mystring, fruit_e_to_r, fruit_r_to_e

    string = mystring.get()

    if string in fruit_e_to_r:
        print(fruit_e_to_r[string])
    
    elif string in fruit_r_to_e:
        print(fruit_r_to_e[string])

    else:
        print('This word is not in the dictionary')

def info():
    global mystring1
    print(mystring1())

name = Label(root, text='Введите слово по-русски: ')
name.pack()

entry = tk.Entry(root, textvariable = mystring)
entry.pack()

button_get = tk.Button(root, text='Перевести', command=getvalue)
button_get.pack()

label_data = Label(root, fg='red')
label_data.pack(side=LEFT, pady=10)

entry = tk.Entry(root, textvariable=mystring1)
entry.pack()

label = Label(root, text='Английский язык')
label.pack()

root.mainloop()



RE: Tkinter | entry output. - Yoriz - Sep-25-2021

The line global mystring, fruit_e_to_r, fruit_r_to_e is not required
to change the value of the entry that uses tk.StringVar mystring1 use it's set method
mystring1.set(fruit_e_to_r[string])