Yaros
Yaros

Reputation: 164

Kivy app can't find/read my txt file in root directory Android

I created an app that just reads my txt and prints the contents to the screen with a Label, but it can't find my txt when I run the app on android, on windows works fine. Here is my code:

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout

class MainApp(App):
    def build(self):
        fl = FloatLayout()
        fl.add_widget(Label(text=open("settings.txt", "r").read(), halign="center"))
        return fl

MainApp().run()

What is wrong? And I will not use ConfigParser because it's already used in my project, this is just a sample code that I created for this question.

Any help will be appreciated

Upvotes: 3

Views: 1145

Answers (2)

John Anderson
John Anderson

Reputation: 39052

In your buildozer.spec file modify the line:

source.include_exts = py,png,jpg,kv,atlas

to:

source.include_exts = txt,py,png,jpg,kv,atlas

And verify that you have not excluded txt files elsewhere in the spec file.

Upvotes: 1

inclement
inclement

Reputation: 29488

open("settings.txt", "r").read()

This code attempts open an already-existing file named "settings.txt" in the current directory. You haven't explained the nature of the failure, but presumably it doesn't exist. You also haven't explained why you think that file would exist, so we can't point out any specific mistake.

The general solution is, do something to make that file exist. Perhaps you have omitted it from the packaged file types.

Upvotes: 0

Related Questions