Feb-17-2023, 05:40 AM
(This post was last modified: Feb-17-2023, 05:40 AM by deanhystad.)
This is easy to figure out if you let Python help.
First you look at the error message:
Next search for every line that includes entBookTitle and focus on lines that assign a value to entBookTitle. In your posted code this only happens on line 17.
First you look at the error message:
Error: book = Book(self.entBookTitle.get(), self.entBookISBN.get(), self.entBookAuthor.get(), self.entBookYear.get())
^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'
The next thing I would do is put a breakpoint on line 32 and run the program in the debugger, or add a print command before line 32 to display the value of self.entBookTitle.def SaveBook(self): print(self.entBookTitle) book = Book(self.entBookTitle.get(), self.entBookISBN.get(), self.entBookAuthor.get(), self.entBookYear.get())This would verify that self.entBookTitle is indeed None.
Next search for every line that includes entBookTitle and focus on lines that assign a value to entBookTitle. In your posted code this only happens on line 17.
self.entBookTitle = ttk.Entry(frameRight, font=('Helvetica', 12), width=20).pack(padx=10, pady=10)Using the debugger I would set a breakpoint on line 18, or add a print statement right after line 17 to see the value of self.entBookTitle right after the assignment. The value would indeed be Null. Now you have isolated the problem to 1 line which contains an assignment and two function calls. These are the two function calls:
ttk.Entry(frameRight, font=('Helvetica', 12), width=20) .pack(padx=10, pady=10)One of these returns None. I would rewrite like this:
self.entBookTitle temp = ttk.Entry(frameRight, font=('Helvetica', 12), width=20) print("entry", temp) temp.pack(padx=10, pady=10) print("pack", temp) self.entBookTitle = tempRun the code and you would see that "ttk.Entry(frameRight, font=('Helvetica', 12), width=20)" returns a ttkEntry object and pack() returns None. Armed with that information you would quickly realize that you need to break up creating and packing the entry widget.
self.entBookTitle = ttk.Entry(frameRight, font=('Helvetica', 12), width=20) self.entBooktitle.pack(padx=10, pady=10)I'm confident that you would have solved this problem quite quickly if you did a little poking around instead of immediately throwing up your hands in frustration. Give yourself some credit.