-1

Can anyone please tell me, why I get the error 'NoneType' object has no attribute 'get'?

import tkinter as tk
from tkinter import messagebox

class App(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.lab1 = tk.Label(text="Abfahrtsort").grid(row=0, column=0, sticky="w")
        self.start = tk.Entry(self).grid(row=0, column=1)
        self.lab2 = tk.Label(text="Zielort").grid(row=1, column=0, sticky="w")
        self.end = tk.Entry(self).grid(row=1, column=1)
        self.button = tk.Button(self, text="Anzeigen", command=self.on_button).grid(row=2, column=1)

    def on_button(self):
        messagebox.showinfo(self.entry.get())

app = App()
app.mainloop()
D. Studer
  • 1,711
  • 1
  • 16
  • 35
  • Change `self.entry.get()` to `self.end.get()`. You are trying to use `get()` on a non-existent `self.entry`. Seeing that you have defined your entry field as `self.end` you need to change your messagebox statement to reflect the same. On top of that you need to use `grid()` on a new line separate from where you define your entry field. – Mike - SMT Dec 31 '18 at 15:06
  • If you had searched this site with that exact error message you would have found an answer. – Bryan Oakley Dec 31 '18 at 15:33

1 Answers1

0

You have two issues here in your code. The 1st one is your grid() statement.

Change these:

self.start = tk.Entry(self).grid(row=0, column=1)
self.end = tk.Entry(self).grid(row=1, column=1)

To this:

self.start = tk.Entry(self)
self.start.grid(row=0, column=1)

and this:

self.end = tk.Entry(self)
self.end.grid(row=1, column=1)

The 2nd is your messagebox statement.

Change this:

messagebox.showinfo(self.entry.get())

To this:

messagebox.showinfo(self.start.get())

Or this depending on what entry you are trying to access:

messagebox.showinfo(self.end.get())

You will also need to correct the indention of your self.end and self.button to be inline with everything else in your __init__ method.

Mike - SMT
  • 14,784
  • 4
  • 35
  • 79