3

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

Yaros
  • 155
  • 9
  • You use only a file name. Not a full path. From which full directory path should your file be loaded? Who placed that file there and how? You say root directory but people have different ideas about what the root directory would be. Better name full path. – blackapps Oct 17 '20 at 11:12
  • @blackapps How can I do that in kivy android? – Yaros Oct 17 '20 at 18:35

2 Answers2

1

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.

John Anderson
  • 35,991
  • 4
  • 13
  • 36
0
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.

inclement
  • 29,124
  • 4
  • 48
  • 60