使用Kivy开发Python计算器时Button控件初始化报错求助
Looking at your error log, the root cause is crystal clear: you’re passing a non-existent property text_ (with a trailing underscore) when creating a Kivy Button instance, but the valid property for setting button text is text (no trailing underscore).
What’s Causing the Error?
The traceback explicitly calls out the issue:
TypeError: Properties ['text_'] passed to init may not be existing property names. Valid properties are [..., 'text', ...]
Kivy’s Button widget inherits from Label, which uses the text attribute to control displayed text. Your typo (text_ instead of text) breaks the widget initialization process because Kivy doesn’t recognize this invalid property name.
How to Fix It
Head to line 27 of your main.py (as referenced in the log) where you create the Button, and correct the property name:
Incorrect Code:
button = Button( text_="1", # Trailing underscore makes this invalid # Other button properties... )
Correct Code:
button = Button( text="1", # Use the valid 'text' property # Other button properties... )
Next Steps
After fixing this typo, re-run your calculator project. This specific initialization error should be resolved immediately. If you hit other issues later, double-check for similar property name typos—Kivy strictly enforces matching valid widget properties.
内容的提问来源于stack exchange,提问作者Max Legav

