我正在嘗試爲學校項目製作公式計算器。我正在嘗試使用.get tkinter方法來獲取Entry中的內容。它總是發送一個錯誤。儘管如此,我不想將它寫入課堂。tkinter .get方法無法正常工作
這不是最終的代碼。
from tkinter import *
def speedCalc():
_distance = spDistance.get()
_time = spTime.get()
spDistance = Entry(speed).grid(row=1, column=1)
spTime = Entry(speed).grid(row=2, column=1)
spSpeed = Entry(speed).grid(row=3, column=1)
spConvert = Button(speed, text="Calculate", command=speedCalc)
spConvert.grid(row=4, column=1)
當我執行的代碼,它說,這在控制檯上:
Exception in Tkinter callback
Traceback (most recent call last):
File"C:\Users\JackP\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:/Users/JackP/Desktop/Python Projets/Formula App/4. Extention.py", line 25, in speedCalc
_distance = spDistance.get()
AttributeError: 'NoneType' object has no attribute 'get'
這個問題已經被問了無數次。請google [AttributeError:'NoneType'對象沒有'get'屬性](https://www.google.com/search?source=hp&q=AttributeError%3A+%27NoneType%27+object+has+no+attribute+% 27get%27&OQ = AttributeError的%3A +%27NoneType%27 + +對象+有沒有+屬性+%27get%27&gs_l = PSY-ab.3 ... 325.325.0.634.1.1.0.0.0.0.0.0..0.0 .... 0 ... 1.1.64.psy-ab..1.0.0 .... 0.h1eEyi4YuD0),你會得到你的答案。 –
謝謝。我四處尋找錯誤的東西。 – JackHumphries