Python Forum
Tkinter | entry output.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter | entry output.
#1
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()
Reply
#2
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])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter Exit Code based on Entry Widget Nu2Python 6 393 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  [Tkinter] Update variable using tkinter entry methon drSlump 6 667 Oct-15-2021, 08:01 AM
Last Post: drSlump
  .get() from generated Entry widgets in tkinter snakes 4 1,129 May-03-2021, 11:26 PM
Last Post: snakes
  [Tkinter] acceleration of data output in treeview tkinter Vladimir1984 4 1,371 Nov-21-2020, 03:43 PM
Last Post: Vladimir1984
  Entry Validation in tkinter shahulvk 4 3,231 Oct-28-2020, 10:12 PM
Last Post: joe_momma
  Displaying output in GUI ( Tkinter) Zouloutamtam 7 6,986 Sep-29-2020, 02:08 PM
Last Post: Zouloutamtam
  [Tkinter] Getting Input from Tkinter Entry juliabrushett 6 15,682 May-30-2020, 03:29 PM
Last Post: Larz60+
  Converting Entry field value to integer in tkinter scratchmyhead 2 2,733 May-11-2020, 03:41 PM
Last Post: scratchmyhead
  [Tkinter] Tkinter adding entry values scratchmyhead 1 989 May-04-2020, 05:21 AM
Last Post: Yoriz
  [Tkinter] Entry box not showing 2 decimal places Chuck_Norwich 3 2,322 Apr-24-2020, 05:28 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020