-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Description
I successfully convert python file into apk, but the button doesn't work. The button can work on my computer, I don't know why no response when I'm touching the button.
Here is my python code
from kivymd.app import MDApp
from kivy.core.window import Window
from kivy.uix.screenmanager import Screen
from kivy.properties import StringProperty
from kivymd.uix.snackbar import Snackbar
from kivy.uix.label import Label
from kivy.network.urlrequest import UrlRequest
import certifi
import os
class HomeScreen(Screen):
pass
class MainApp(MDApp):
name = StringProperty()
category = StringProperty()
area = StringProperty()
image = StringProperty()
url = StringProperty()
youtube = StringProperty()
def __init__(self,**kwargs):
Window.size = (1200,1600)
super().__init__(**kwargs)
def on_start(self):
os.environ['SSL_CERT_FILE'] = certifi.where()
UrlRequest('https://www.themealdb.com/api/json/v1/1/random.php', on_success=self.success, on_failure=self.failure, on_error=self.error)
def success(self, urlrequest, result):
ingredient_list = self.root.ids['home'].ids['ingredient_list']
print(result)
self.youtube = result['meals'][0]['strYoutube']
self.name = result['meals'][0]['strMeal']
self.category = result['meals'][0]['strCategory']
self.area = result['meals'][0]['strArea']
self.image = result['meals'][0]['strMealThumb']
self.url = result['meals'][0]['strSource']
for i in range(1,21):
if result['meals'][0][f'strIngredient{i}'] != '':
l = Label(text=result['meals'][0][f'strIngredient{i}'],color=(0,0,0,1))
ingredient_list.add_widget(l)
def error(self, urlrequest):
print("error")
Snackbar(text='Url is not available').show()
def failure(self, urlrequest):
print("failure")
Snackbar(text='Url is not available').show()
**def view(self):**
if self.url != '' and self.youtube == '':
Snackbar(
text=self.url,
size_hint_x=2
).show()
if self.youtube != '' and self.url == '':
Snackbar(
text=self.youtube,
size_hint_x=2
).show()
if self.youtube != '' and self.url != '':
Snackbar(
text=self.youtube,
size_hint_x=2
).show()
if self.youtube == '' and self.url == '':
Snackbar(text='Url is not available').show()
MainApp().run()
kv file
ScreenManager:
HomeScreen:
id:home
name:'home'
<HomeScreen>:
FloatLayout:
**MDRaisedButton:**
pos_hint:{'top':.27,'right':.65}
size_hint:.3,.05
text:'View'
on_press: app.view()
Label:
text: 'Ingredients'
font_size:40
pos_hint:{'top':.23,'right':1}
size_hint:1,.1
color:1,0,0,1
ScrollView:
pos_hint:{'top':.15,'left':1}
size_hint:1,.15
GridLayout:
id: ingredient_list
cols:1
size_hint_y: None
height: self.minimum_height
row_default_height:'50dp'
row_force_default: True
spec file
# (str) Title of your application
title = My MealApp
# (str) Package name
package.name = myMealApp
# (str) Package domain (needed for android/ios packaging)
package.domain = org.test
# (str) Source code where the main.py live
source.dir = .
# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,ttf,db,txt,url
# (list) List of inclusions using pattern matching
#source.include_patterns = assets/*,images/*.png
# (list) Source files to exclude (let empty to not exclude anything)
#source.exclude_exts = spec
# (list) List of directory to exclude (let empty to not exclude anything)
#source.exclude_dirs = tests, bin
# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg
# (str) Application versioning (method 1)
version = 0.1
# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]
# version.filename = %(source.dir)s/main.py
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy==2.0.0rc1,kivymd,chardet,idna,certifi,urllib3,requests,openssl,android
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels