-2
from tkinter import *
root = Tk()

root.title("Matchstick Game")
root.iconbitmap("match.ico")
root.geometry("1000x580")

H = Entry(root, width = 80, fg = 'red').pack()
def clickme():
mylabel = Label(root, text = "Hello" + H.get()).pack()

my_button = Button(root, text = "whats your name", 
padx=10,pady=10,bg='white',fg='green',command=clickme).pack()

root.mainloop()

I am getting this error: AttributeError: 'NoneType' object has no attribute 'get'

Tails
  • 1

2 Answers2

0

Jason Harper in the comments has the right answer. Separating the .pack() statements from the Label and Entry definitions will fix the error.

Here is what I got

import tkinter as tk

root = tk.Tk()

root.title("Matchstick Game")
#root.iconbitmap("match.ico")
root.geometry("1000x580")

H = tk.Entry(master = root, width = 80, fg = 'red')
H.pack()

def clickme():
    mylabel = tk.Label(root, text = ( "Hello" + H.get()))
    mylabel.pack()

my_button = tk.Button(root, text = "whats your name", 
padx=10,pady=10,bg='white',fg='green',command=clickme)

my_button.pack()

root.mainloop()

Hope that helped.

t.o.
  • 832
  • 6
  • 20
0

pack() function of Entry returns None, so you're storing None in H. What you want to do is store the Entry object in H, and then call pack method on it later.

H = Entry(root, width = 80, fg = 'red')
H.pack()
Gyanendra
  • 31
  • 1
  • 6