我是一名正在学习 python 的高中生,我对为什么在这个脚本中收到错误消息感到有点困惑。它应该提示用户输入他们的年龄信息,然后以天、小时和分钟为单位返回信息。我正在使用 Graphics.py 模块来完成此操作。我得到的错误是:
how old are you.py", line 17, in <module>
years=entry1.getText()
AttributeError: 'NoneType' object has no attribute 'getText'
我知道该模块已正确安装,因为 getText 函数适用于另一个脚本。我的代码如下所示。谢谢你的帮助!
from graphics import*
win=GraphWin('How Old Are You?',250,500)
win.setBackground ('Gray')
entry1= Entry(Point(125,100),10).draw(win)
entry2= Entry(Point(125,200),10).draw(win)
entry3= Entry(Point(125,300),10).draw(win)
Text(Point(125,50),'How many years old are you?').draw(win)
Text(Point(125,150),'What month in the year? (number)').draw(win)
Text(Point(125,250),'How many weeks into the month?').draw(win)
Text(Point(125,25),'When done click outside a box').draw(win)
win.getMouse()
years=entry1.getText()
months=entry2.getText()
days=entry3.getText()
totalDays=(years*365)+(months*30)+(days)
totalHours=((years*365)+(months*30)+(days))*24
totalMinutes=(((years*365)+(months*30)+(days))*24)*60
Text(Point(125,350),totalDays)
Text(Point(125,400),totalHours)
Text(Point(125,450),totalMinutes)