i have a code that loads an image online with the AsyncImage module in kivy. i wrote the code in python3 which runs well on the pc but doesnt work on a packaged apk. i think this is because i packaged it using python2.7 buildozer. thanks an image showing the error in logcat
this is the code
class Gallery(Screen,GridLayout):
scroller = ObjectProperty(None)
grid = ObjectProperty(None)
def __init__ (self,**kwargs):
super(Gallery, self).__init__(**kwargs)
if len(self.ids.grid.children) == 0:
for i in range(13):
src = "http://placehold.it/480x270.png&text=slide-%d&.png" % i
image = MyTile(source=src, allow_stretch=True)
self.ids.grid.add_widget(image)
It seems that your APK is missing ssl support (the URL is redirecting you to an https site...)
try adding:
requirements = kivy,OTHER_STUFF_YOU_NEED,openssl
to your buildozer spec.
EDIT:
as #DipanshuJuneja commented, as of this time the solution works with python2 but not on 3 :(
Related
Pls help. I'm trying to learn the basics but it won't display exactly as I expected it to. Only blank screen appears and no button. importing button also does not help.
main.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
[enter image description here][1]
class NoobWidget(BoxLayout):
pass
class NoobApp(App):
def build(self):
return NoobWidget()
if __name__ =="__main__":
NoobApp().run()
kivytesta.kv
<NoobWidget>
Button:
text:"Click me"
Label:
text:"Not Clicked Yet"
You must load the kv file:
class NoobApp(App):
def build(self):
Builder.load_file('kivytesta.kv')
return NoobWidget()
I haven't tried the suggested fix advised but after installing python on a new laptop, I saw in the release notes that back then that latest version of kivy was not compatible to the python 3.x version I was using. Now I am using the latest version of Kivy 2.0.0 and it worked.
I have a simple Kivy app to try out a clickable link opening a Web site. The code is:
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.label import Label
import webbrowser
class TestApp(App):
def build(self):
ref = '[ref=https://kivy.org/doc/stable/]' + 'Kivy documentation' + '[/ref]'
link = Label(text=ref, markup=True, on_ref_press=self.OpenLink)
return link
def OpenLink(self, label, ref):
webbrowser.open(ref)
if __name__ == '__main__':
TestApp().run()
When I run this app in the Kivy Launcher on Android, tapping the link works and opens the url in the browser. However, when I run the compiled app nothing happens when I tap the link.
In the buildozer.spec file I have:
android.permissions = INTERNET
According to all information I have been able to find, this is all I should need. What else am I missing?
I have tried logging the app using adb logcat but I can't see anything relating to the problem.
i am new to kivy and would like some help guys .
i am building a Kivy App with buildozer for android , that uses an outsource API from cryptocompare.com
it is a very simple app that shows the Cryptocurrency prices , live updated.
the app crashes instantly when opened ..
i removed the API and created a Dict instead, just to test if the App will work or not , and the app runs perfectly on android .. when i put back the API , it just keep crashing .
note that the app works fine on Pycharm with no error .. also the Buildozer gives no error ..
i've been trying to find out the problem for so long .
tried every possible way . no luck.
almost included everything in android.permissions with no luck also .
this is my app code
from kivymd.app import MDApp
from kivymd.uix.screen import Screen
from kivymd.uix.list import MDList, TwoLineListItem
from kivy.uix.scrollview import ScrollView
from kivy.network.urlrequest import UrlRequest
class CryptoPrices(MDApp):
def build(self):
screen = Screen()
scroll = ScrollView()
listview = MDList()
scroll.add_widget(listview)
def got_json(req, result):
for x, y in result.items():
name = x
symbol = str(y["USD"]) + " USD"
item1 = TwoLineListItem(text=name, secondary_text=str(symbol))
listview.add_widget(item1)
req = UrlRequest('https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC,BCH,LTC,XLM,DASH,XEM,LIBRA,BNB,ETH,XMR,XRP,LTC&tsyms=USD', got_json)
screen.add_widget(scroll)
return screen
if __name__ == '__main__':
CryptoPrices().run()
link to buildozer.specs
https://textuploader.com/1f7ie
link to log file
https://textuploader.com/1f7ii
Two possible issues:
You may need to request runtime permissions. See runtime permissions
You might need to add requests to your requirements in the spec file.
From the buildozer.spec file, you have to set internet permissions.
By default this option is commented, just uncomment it and the app should work fine.
The logfile that you have added is buildozer log when the app is being built. To get the app log when it's running, add the logcat function (buildozer android logcat) In app logs you can find what causing your app to crash any requirements or permission or anything else
I'm planning to use kivy to develop an app related to one of my project. But still I couldn't find a way to make the app run in background and while a certain condition is satisfied I need it to display a push notification in mobile. How can I add push notification feature in kivy? Please let me know if someone know how to make it work. (Note - Even the app is closed in mobile it should run in background..).
I can't tell you how to keep running in the background (because I don't know either) but I can show you how to notify.
by the way,plyer doesn't work as well as windows on android so you should throw with java lib jnius
codes is here:
from kivy.app import App
from kivy.uix.button import Button
from jnius import autoclass
def notify(*args):
AndroidString = autoclass('java.lang.String')
PythonActivity = autoclass('org.kivy.android.PythonActivity')
NotificationBuilder = autoclass('android.app.Notification$Builder')
Context = autoclass('android.content.Context')
Drawable = autoclass('org.test.notify.R$drawable')
icon = Drawable.icon
notification_builder = NotificationBuilder(PythonActivity.mActivity)
notification_builder.setContentTitle(AndroidString('Title'.encode('utf-8')))
notification_builder.setContentText(AndroidString('Message'.encode('utf-8')))
notification_builder.setSmallIcon(icon)
notification_builder.setAutoCancel(True)
notification_service = notification_service = PythonActivity.mActivity.getSystemService(Context.NOTIFICATION_SERVICE)
notification_service.notify(0,notification_builder.build())
class NotifyApp(App):
def build(self):
return Button(text="notify", on_press=notify)
if __name__ == '__main__':
NotifyApp().run()
if you keep getting errors,look here
I am trying to use pygubu from the first time to make better GUI's. I have installed it using pip and it has installed correctly. However when I try and run the example code Here (At the bottom of the web page) I get the error
AttributeError: module 'pygubu' has no attribute 'Builder'
I don't know if this code is correct or not. I have looked for ways to use this tool but all I can find are links and videos for installing it. I have also tried This video but can't figure out how to open/run/use. I am using python-idle if that is the issue. The code (if you don't want to follow the link) is:
# helloworld.py
import tkinter as tk
import pygubu
class HelloWorldApp:
def __init__(self):
#1: Create a builder
self.builder = builder = pygubu.Builder()
#2: Load an ui file
builder.add_from_file('helloworld.ui')
#3: Create the mainwindow
self.mainwindow = builder.get_object('mainwindow')
def run(self):
self.mainwindow.mainloop()
if __name__ == '__main__':
app = HelloWorldApp()
app.run()
I would appreciate any help. Also when I try installing it again - just to check - I get:
Pygubu is an application. Find it in files from C: drive. The code:
# helloworld.py
import tkinter as tk
import pygubu
class HelloWorldApp:
def __init__(self):
#1: Create a builder
self.builder = builder = pygubu.Builder()
#2: Load an ui file
builder.add_from_file('helloworld.ui')
#3: Create the mainwindow
self.mainwindow = builder.get_object('mainwindow')
def run(self):
self.mainwindow.mainloop()
if __name__ == '__main__':
app = HelloWorldApp()
app.run()
Is run after you have created your UI (The format that this application uses) and that the name of the UI specified is helloworld.ui.
Note that instead of helloworld.ui in the following line:
builder.add_from_file('helloworld.ui') You should insert the filename
(or path) of your just saved UI definition.
Note also that instead of 'mainwindow' in the following line:
self.mainwindow = builder.get_object('mainwindow') You should have the
name of your main widget (the parent of all widgets), otherwise you
will get an error similar to the following:
Exception: Widget not defined.
This link explains the usage better than one stated in question