0

I'm trying to print the value xf_in which is entered in the GUI.

However, I get the following error message when i press the run button:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\My_Name\Anaconda3\lib\tkinter\__init__.py", line 1699, in __call__
    return self.func(*args)
  File "C:/Users/My_Name/Python Scripts/test/gui.py", line 6, in EP
    xf_In = tk.get(e_xf)
AttributeError: module 'tkinter' has no attribute 'get'

I've tried to find the source of the error online but to no avail.

Thanks in advance for any help

My code is as follows:

import tkinter as tk
from PIL import ImageTk as imtk
from PIL import Image as im

def EP(): # Enter inputs from values typed in
      xf_In = tk.get(e_xf)
      print(xf_In)

root = tk.Tk()

l_xf = tk.Label(root, text="xA of Feed").grid(row=0)

e_xf = tk.Entry(root).grid(row=0, column=1)       


run = tk.Button(root, text="Run", command=EP).grid(row=8, column=0, columnspan = 2)

img = imtk.PhotoImage(im.open("x.png"))
panel = tk.Label(root, image = img).grid(row = 0, column = 2, rowspan = 7)

root.mainloop()
Ayrton Bourn
  • 365
  • 5
  • 16
  • 1
    What do you think `tk.get(e_xf)` is going to do? Are you trying to get the value of the `e_xf` widget? There are many examples on this site and all over the internet for how to get the value of an entry widget, have you done any research at all? – Bryan Oakley May 25 '17 at 15:27
  • I had tk. because i got the no .get attribute error when i had e_xf.get(). yes I am trying to get the value of the e_xf entry widget. I have done research into this but couldnt find an answer hence why i am posting here. The issue turned out to be due to the fact I was calling the grid value rather than the entry value – Ayrton Bourn May 25 '17 at 15:28

1 Answers1

0

As the error message indicates, the tk module does not have a function named get. It might have plenty of classes whose instances have a get method, but you can't access them the way you're doing.

If you're trying to get the contents of the Entry, you should assign it to a name, and call get on that instead:

def EP(): # Enter inputs from values typed in
      xf_In = e_xf.get(e_xf)
      print(xf_In)

#...

e_xf = tk.Entry(root)
e_xf.grid(row=0, column=1)

Note that this assignment is different from doing e_xf = tk.Entry(root).grid(row=0, column=1). If you do that, then e_xf will be bound to the return value of grid, rather than the Entry instance. grid returns None, so trying to call get on that would only give you an AttributeError. Related reading: Why do my Tkinter widgets get stored as None?

Kevin
  • 74,910
  • 12
  • 133
  • 166
  • xf_In = e_xf.get(e_xf) AttributeError: 'NoneType' object has no attribute 'get' – Ayrton Bourn May 25 '17 at 15:27
  • Sorry, I forgot to mention the grid assignment problem in my first draft. Try changing the assignment of `e_xf` as well and see if that helps. – Kevin May 25 '17 at 15:28