I am getting error: 'NoneType' object has no attribute 'get', and I can't quite figure out how to solve said problem

I am getting error: 'NoneType' object has no attribute 'get', and I can't quite figure out how to solve said problem

我正在编写代码,要求通过 Tkinter 进行数字输入。将在执行掷两个骰子功能的循环中用作周长的位置。我收到错误消息:'NoneType' 对象没有属性 'get',我不太明白如何解决上述问题。

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()

您丢失了对 Entry 的引用,因为 e 被设置为 pack() 函数的输出,returns None 在给出进入地理包装器。

要在 e 中正确引用 Entry,请将 .pack() 命令分开一行,例如:

   e = Entry(root, width=50)
   e.pack()