无法从kivymd.uix.toolbar导入MDToolbar的错误求助
Hey there! Let's get that import error sorted out quickly. The issue here is a module structure change in newer KivyMD versions:
In recent releases of KivyMD, the MDToolbar component was moved from the kivymd.uix.toolbar module to kivymd.uix.topappbar. Your current import statement is pointing to the old location, which is why Python can't find it.
Solution 1: Update the Import Statement (Recommended)
Replace your existing import line for MDToolbar with this:
from kivymd.uix.topappbar import MDToolbar
Here's your full code with the corrected import:
from kivymd.uix.screen import MDScreen from kivymd.app import MDApp from kivy.uix.image import Image from kivymd.uix.button import MDFillRoundFlatIconButton, MDFillRoundFlatButton from kivymd.uix.textfield import MDTextField from kivymd.uix.label import MDLabel from kivymd.uix.topappbar import MDToolbar # Updated import class ConverterApp(MDApp): def build(self): screen = MDScreen() self.toolbar = MDToolbar(title = 'Binary to Decimal') self.toolbar.pos_hint = {'top':1} screen.add_widget(self.toolbar) return screen if __name__ == '__main__': ConverterApp().run()
Solution 2: Revert to an Older KivyMD Version (If Needed)
If you specifically need to use the old module structure for some reason, you can install a version of KivyMD where MDToolbar was still in kivymd.uix.toolbar (like version 0.104.2):
pip install kivymd==0.104.2
Note that this isn't long-term recommended, as newer versions include bug fixes and new features.
After making either change, run your code again—it should work without the import error!
内容的提问来源于stack exchange,提问作者prajwal hiremath




