I am writing code that asks for a numerical input through Tkinter. Where that is going to be used as a perimeter in a loop that carries out the function of rolling two dice. I am getting error: 'NoneType' object has no attribute 'get', and I can't quite figure out how to solve said problem.
from tkinter import *
root = Tk()
numlist = []
question = Label(root, text = "how many times do you want to roll the two dice? : ").pack()
def myClick():
value = e.get() + 0
return int(value)
for u in range(value):
numlist.append(random.randint(1,6)+random.randint(1,6))
print(dict((r, numlist.count(r) ) for r in sorted(numlist)))
e = Entry(root, width=50).pack()
B_Enter = Button(root, text="Enter", command=myClick).pack()
root.mainloop()
You lose the reference to the Entry
because e
is set to the output of the pack()
function, which returns None
after giving the entry to the geography packer.
To get the correct reference to the Entry
in e
, separate the .pack()
command to a separate line, e.g.:
e = Entry(root, width=50)
e.pack()