'NoneType' 使用 Tkinter 时对象没有属性 'get'

'NoneType' object has no attribute 'get' while using Tkinter

使用以下代码尝试将用户输入存储在条目对象中作为变量(CIK、As_of_date、Number_of_filings、归档)。我收到以下错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "<ipython-input-1-51f58e22bad3>", line 27, in get_entries
    CIK = CIK_Entry.get()
AttributeError: 'NoneType' object has no attribute 'get'


window = Tk()
window.title('SEC Scraper')


# Create the Header
Header = Label(text= "Filing Data Collection").grid(row=0, column=0)
# Text Inputs

CIK_Label = Label(text="CIK Number: ").grid(row=1, column=0)
CIK_Entry = Entry(window).grid(row=1, column=1)
As_of_Date_Label = Label(text="Filings as of (YYYYMMDD format): ").grid(row=1, column=2)
As_of_Date_Entry = Entry(window).grid(row=1, column=3)
Number_of_filings_Label = Label(text="Number of Filings: ").grid(row=1, column=4)
Number_of_filings_Entry = Entry(window).grid(row=1, column=5)
Filing_Type_Label = Label(text="Filing Type: ").grid(row=1, column=6)

# Filing Type Drop Down Menu 
Filing_choices = ['10-K', '10-Q', '8-K', 'S-8', 'S-1', '10-K/A', '10-Q/A', '8-K/A', 'S-8/A', 'S-1/A']
Filing_Entry = Combobox(window, width=10, values=Filing_choices).grid(row=1, column=7)

def get_entries():
    CIK = CIK_Entry.get()
    As_of_Date = As_of_Date_Entry.get()
    Number_of_filings = Number_of_filings_Entry.get()
    Filing = Filing_Entry.get()

Enter_Button = Button(window, text="Enter", command=get_entries)
Enter_Button.grid(row=1, column=8)

window.mainloop()

我认为你应该在单独的一行中调用网格方法。 在您的设置中,CIK_Entry 指的是 .grid() 方法的 return 值,即 None.

您希望它指向 tk.Entry return 值。

CIK_Entry = Entry(window)
CIK_Entry.grid(row=1, column=1)