-1
from tkinter import *

main = Tk()

e = Entry(main).pack()

main.configure(bg = "Black")

s = e.get()

main.mainloop()

but then I get this error:

Traceback (most recent call last):
  File "//agsb2/2014intake/kfullman14/My Documents/CICT/Programming U6/Python/Python Challenges/Tkinter test.py", line 9, in <module>
    s = e.get()
AttributeError: 'NoneType' object has no attribute 'get'

Any help would be greatly appreciated. Thanks in advance.

Kit Fullman
  • 19
  • 1
  • 6

1 Answers1

0

Try this:

from tkinter import *


def button():
    s = e.get()
    label.config(text ='See? There is a difference.You entered %s.' %(s))

main = Tk()

e = Entry(main, bd=5, width=40)

main.configure(bg = "Black")
button = Button(main, text="Do Something", command=button)
label = Label(main, text="I am needed to show the difference.")

e.pack()
label.pack()
button.pack()

main.mainloop()

You did declare the variable but you never said how and when to use it. Hence, you did not see any change. In the example above you have a button that reads the Input and uses it to change a label.

Blue
  • 113
  • 7
  • Thanks this worked – Kit Fullman Jul 12 '18 at 13:04
  • 1
    In your explanation you ignored the part that was actually causing the error. In `e = Entry(main).pack()`, `e` is assigned the return value of `pack()` which is `None` and `None` has no `get()` attribute. By changing this to `e = Entry(main)` `e.pack()`, `e` now is an `Entry` object which does have a `get()` attribute. – fhdrsdg Jul 12 '18 at 13:18
  • The error was added later. Just happy to help. – Blue Jul 13 '18 at 06:46