0

I want to create window, which takes input from the user and after clicking show, it prints whatever has been inputted:

    import sys
    import tkinter as tk
    import time
    class Application(tk.Frame):
       def __init__(self):
       super().__init__()
    self.pack()
    self.create_widgets()

def create_widgets(self):

    self.hi_there = tk.Button(self,text = "show",command = 
    self.Show_enter,fg="red",bg="blue")
    self.hi_there.pack(side = "right")

    self.UN = tk.Label(text="User Name").pack(side="left")
    self.enter = tk.Entry(bd=5, bg="red").pack(side="right")







def Show_enter(self):
    s = self.enter.get()
    print(s)






  root = tk.Tk()
  app = Application()
  app.master.title("coool")
  app.mainloop()

However, i get the error:

AttributeError: 'NoneType' object has no attribute 'get'

Skulli01
  • 25
  • 4
  • don't use `pack()` on the same line you declare a widget if you want to keep a reference for this widget, `pack` returns a `None` value – PRMoureu Jun 16 '18 at 08:50
  • Can you fix your indentation and remove the unnecessary whitespace? – jedwards Jun 16 '18 at 08:50

1 Answers1

0

Dont use .pack() directly. Here is an example of how you can do it:

self.entry = Entry(root, width=25)
self.entry.pack()

def get_value(self):
    val = self.entry.get()
    print(val)
Bibek Bhandari
  • 422
  • 1
  • 4
  • 15