Nguyen Viet Khang
Nguyen Viet Khang

Reputation: 67

can not save kivy file. How to save kivy file?

I can not save kivy file to my computer. Do you have any suggestions? On my computer, it saves as better.kv.py and when I try to put the file extension on it still doesn't save as better.kv instead it looks like this enter image description here

here is the code that I am working with

main.py

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget

class MyGrid1(Widget):pass

    

class BetterApp(App):
    def build(self):
        return MyGrid1()


if __name__ == '__main__':
    BetterApp().run()

and better.kv

<MyGrid1>:
    Label:
        text: ('[b]Hello[/b] [color = ff0099]World[/color]\n')

when I run better.kv here is the error

line 1
     <MyGrid1>:
stderr:     <MyGrid1>:
     ^
stderr:     ^
 SyntaxError: invalid syntax
stderr: SyntaxError: invalid syntax

Thank you

Upvotes: 1

Views: 551

Answers (3)

Nguyen Viet Khang
Nguyen Viet Khang

Reputation: 67

If you run into this problem:

save the .py file as the same place as the .kv

secondly:

you have to run file as scrip or redirect main.py to the file

Upvotes: 0

CrazyChucky
CrazyChucky

Reputation: 3518

You shouldn't run better.kv. You run main.py and it accesses better.kv automatically.

Note that as Nour-Allah Hussein pointed out, you still have the inconsistent name of MyGrid / MyGrid1. If you run main.py as-is, return MyGrid() will throw a NameError because you haven't defined anything named MyGrid.

Upvotes: 1

Nour-Allah Hussein
Nour-Allah Hussein

Reputation: 1459

Let us verify some points:

First Point:

your application folder name is better so your kv file should be better.kv, as the same folder name but with extension kv

Second Point:

in class BetterApp(App): function def build(self) you use return MyGrid(), but the intended class in your code is different, it is MyGrid1 as in your code class MyGrid1(Widget): pass so your code does not work, because you initiate MyGrid and not MyGrid1

Upvotes: 2

Related Questions