Tkinter: AttributeError: NoneType object has no attribute attribute name
The grid
, pack
and place
functions of the Entry
object and of all other widgets returns None
. In python when you do a().b()
, the result of the expression is whatever b()
returns, therefore Entry(...).grid(...)
will return None
.
You should split that on to two lines like this:
entryBox = Entry(root, width=60)
entryBox.grid(row=2, column=1, sticky=W)
That way you get your Entry
reference stored in entryBox
and it's laid out like you expect. This has a bonus side effect of making your layout easier to understand and maintain if you collect all of your grid
and/or pack
statements in blocks.
how to fix AttributeError: 'NoneType' object has no attribute 'get' for tkinter entry
it's entry.grid(...) return None
I think you want
from tkinter import *
root = Tk()
a = Entry(root)
a.grid(row = 0, column = 0)
b = Button(root,text = 'CLICK', command= lambda: test()).grid(row = 2, column = 2)
def test():
print(a.get())
root.mainloop()
NoneType object has no attribute to get (Tkinter)
If you are making an entry, be sure that it is not formatted like this:
r = Entry(root, width=15, bg="white").grid(row=0, column=1)
It should be like this to remove an AttributeError:
r = Entry(root, width=15, bg="white")
r.grid(row=0, column=1)
NoneType' object has no attribute 'get' while using Tkinter
I think you should call the grid method in a separate line,.
In your setup, CIK_Entry refers to the return value of .grid() method, which is None.
You want it to point to the tk.Entry return value.
CIK_Entry = Entry(window)
CIK_Entry.grid(row=1, column=1)
i am getting an AttributeError: 'NoneType' object has no attribute 'get' for my simple GUI program in python
The python shell makes it easy to experiment. Assuming the error is with enter
I just pasted the first part of your code into the shell.
>>> import tkinter as tk
>>> from tkinter import *
>>>
>>> root = tk.Tk()
>>>
>>> enter = tk.Entry(root, width = 35, borderwidth = 5).grid(row = 0, column = 0, columnspan = 3, padx =10 , pady = 10)
>>> repr(enter)
'None'
Yep, its None
. And that's typical. Object methods often don't return their own object. Its convenient for method chaining, but most objects are not designed for that. Just do what examples and tutorials show and put it on a separate line.
import tkinter as tk
from tkinter import *
root = tk.Tk()
enter = tk.Entry(root, width = 35, borderwidth = 5)
enter.grid(row = 0, column = 0, columnspan = 3, padx =10 , pady = 10)
def ButtonClick(number):
print(number)
current = enter.get()
print(current)
# enter.delete(0,END)
# enter.insert(0, current + number)
button1 = tk.Button(root, text="1", bg="yellow",padx = 40, pady= 20, command=lambda: ButtonClick(1)).grid(row = 1, column = 0)
root.mainloop()
python tkinter error AttributeError: 'NoneType' object has no attribute 'insert'
You want to store the Text
object in window
, but you actually store the return value of pack
, which is None. Splitting the line like this should fix the error:
window = Text(self, font=("Helvetica", 14))
window.pack()
Related Topics
How to Get Text of an Element in Selenium Webdriver, Without Including Child Element Text
Python Ftp Get the Most Recent File by Date
Cross-Platform Subprocess With Hidden Window
Converting Epoch Time With Milliseconds to Datetime
How to Convert String Representation of List to a List
How to Import a Module Given Its Name as String
What Do _Init_ and Self Do in Python
How to Simulate Html5 Drag and Drop in Selenium Webdriver
Python Subprocess.Popen "Oserror: [Errno 12] Cannot Allocate Memory"
Python Multiprocessing: Permission Denied
Integer Division by Negative Number
How to Filter Pandas Dataframe Using 'In' and 'Not In' Like in Sql