Please can you tell me why my kivymd app just doesn't run without showing any error

57 Views Asked by At

This is 'my.py` file:

from kivy.uix.button import Button

from kivymd.app import MDApp

from kivymd.uix.boxlayout import MDBoxLayout

from kivymd.uix.floatlayout import MDFloatLayout

from kivymd.uix.card import MDCard

from kivymd.uix.label import MDLabel

from kivy.properties import ListProperty, StringProperty

from kivy.properties import Clock

from kivy.graphics.context_instructions import Color

from kivy.graphics.vertex_instructions import Line, Rectangle, Ellipse

from kivy.lang import Builder

from kivy.uix.screenmanager import ScreenManager, Screen

from kivy.metrics import dp

from kivymd.uix.button import MDIconButton

import sqlite3

import time

import random

from datetime import date

conn = sqlite3.connect('notes.db')

c = conn.cursor()

class ScrnMngr(ScreenManager):

    pass

    

class HomePage(Screen): 

    def __init__(self, **kwargs):

        super(HomePage, self).__init__(**kwargs)

        

class WritePage(Screen): 

    def __init__(self, **kwargs):

        super(WritePage, self).__init__(**kwargs)

kv = '''

ScrnMngr:

    id: ScrnMngr

    HomePage:

        name: 'HomePage'

    WritePage:

        name: 'WritePage'        

        

    

<HomePage>

    MDBoxLayout:

        id: first

        padding: dp(20)

        orientation: 'vertical'

        spacing: '20dp'

        canvas.before:

            Color:

                rgba: 0,1,1,1

            Rectangle:

                pos: 0,0

                size: self.width, self.height

             

        MDLabel:

            text: 'Notes'

            font_size: "40sp"

            size_hint: 1, .02

       

        MDBoxLayout:                              

            size_hint: 1, .2

            MDTextField:

                id: search_field

                hint_text: 'Search note' 

                icon_left: 'magnify'

               #on_text: root.search_folder(self.text)                            

                                          

        MDScrollView:

            id: second

            pos_hint: {'center_x': 0.5, 'center_y': 0.8}                 

            size_hint: 1, .9

            MDBoxLayout:

                id: third

                orientation:"vertical"

                spacing: '20dp'        

                adaptive_height: True

                                                                                                   

                MDGridLayout: 

                    id: book               

                    default_size: 1, dp(30)                           

                    elevation: "8dp"                            

                    default_size_hint: 1, None 

                    spacing: '20dp' 

                    cols: 1

                    padding: 0,50                 

                    size_hint_y: None                        

                    height: self.minimum_height                        

                                   

    MDFloatingActionButton:

        icon: 'page-next' 

        on_release: 

            app.root.current = 'WritePage'

            app.move_to_writepage()

        pos_hint: {'center_x': 0.8 , 'center_y': 0.1}                                               

<WritePage>

    orientation: 'vertical'

    MDBoxLayout: 

        orientation: 'vertical'

        pos_hint: {'center_x': 0.5 , 'center_y': 0.4}           

        

        CodeInput:

            id: title

            hint_text: 'Title' 

            size_hint: 1, .1          

            mode: "fill"     

            fill_color: app.sorbus  

            on_text: root.save_title(self.text, note.text)

        CodeInput:

            id: note

            hint_text: 'Note'

            size_hint: 1, .9   

            mode: 'fill'        

            multiline: True 

            fill_color: app.sorbus

            on_text: root.save_title(title.text, self.text)

    MDIconButton:

        id: look

        icon: 'keyboard-backspace' 

        on_release: 

            app.root.current = 'HomePage'

            app.move_to_homepage()

        pos_hint: {'center_x': 0.07 , 'center_y': 0.96}                

'''

               

class NotepadApp(MDApp):

    title = 'Notepad'

    text_color = ListProperty((1,1,1,1))  

    opp =  ListProperty((0,0,0,0))

    grey = [234/255, 234/255, 234/255, 1]

    sorbus = [221/255, 110/255, 66/255, 1]

    periwinkle = [192/255, 214/255, 223/255, 1]

    champagne = [232/255, 218/255, 178/255, 1]

    colors = [grey,sorbus,champagne]

    no_of_cards = 0

    def build(self): 

        self.root_widget = Builder.load_string(kv)                      

        return self.root_widget

        

if __name__ == '__main__':

    NotepadApp().run()    

    conn.commit()

    conn.close()

I tried using builder, and I just didn't run. I really want to use the kv string.

2

There are 2 best solutions below

1
On

Could you provide more details about the issue? When I executed the code, it appeared to function correctly and a window opened without any problems.

You might consider some simple solutions such as updating the packages:

pip install kivy --upgrade
pip install kivymd --upgrade

Additionally, you could attempt to reinstall the packages:

pip uninstall kivy kivymd
pip install kivy kivymd
0
On

Frankly, it seems you have stupid mistake.

Error shows

>>   44:                    elevation: "8dp"   

TypeError: '<' not supported between instances of 'str' and 'int'

If you compare this line with other lines which use dp (ie. line before with dp(30)) then you should see that it may need dp(8) instead of "8dp". That's all.

Code runs for me when I use dp(8)

elevation: dp(8)

and when I use 8

elevation: 8

I also found documentation for Elevation and there are examples which use numbers without dp