【问题标题】:How to use others package in kivy?如何在kivy中使用其他包?
【发布时间】:2020-01-14 09:39:32
【问题描述】:

我想创建一个 fbchatbot 并与 kivy 一起使用。 为此,我需要导入聊天机器人运行所需的 fbchat-asyncio 模块。

我已尝试在 Buildozer.spec 文件的需求行中包含 fbchat-asyncio 模块。

我还尝试将 fbchat-asyncio 的所有文件夹包和转储到 .Buildozer 文件夹中

该程序在 pc 上运行良好,但是当我使用 apk 文件在手机上运行它时。它在一秒钟内崩溃。我怀疑它是因为它无法识别 fbchat-asyncio


from kivy.uix.widget import Widget
#-*- coding: utf-8 -*-
from kivy.app import App
from fbchat import Client, ThreadType
import asyncio
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.uix.textinput import TextInput

#
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
import time
time.sleep(2)
#create a class to place all widget
class OurGrid(GridLayout):

    def __init__(self,**kwargs): #kwarg mean can handle more parameter
        super(OurGrid,self).__init__(**kwargs)
        self.cols = 1 # can set the layout




        self.inside = GridLayout()
        self.inside.cols = 2

        self.inside.add_widget(Label(text="User Name : ",italic=True,bold=True))
        self.name = TextInput(multiline="false")
        self.inside.add_widget(self.name)

        # self.inside.add_widget(Label(text="Last Name : ",italic=True,bold=True))
        # self.lastName = TextInput(multiline="false")
        # self.inside.add_widget(self.lastName)

        self.inside.add_widget(Label(text="Password : ",italic=True,bold=True))
        self.password = TextInput(multiline="false")
        self.inside.add_widget(self.password)
        self.add_widget(self.inside)
        #label -----
        self.labelShow = Label(text=self.name.text)
        self.add_widget(self.labelShow)
        #add the label
        self.btnLogin = Button(text="Login",font_size=30)
        self.add_widget(self.btnLogin)
        self.btnLogin.bind(on_press=self.press)


        # btn1 = Button(text="Ok", italic=True)
        # btn2 = Button(text="Exit", italic=True)
        # self.add_widget(btn1)
        # self.add_widget(btn2)


        #btnLogin.bind(on_press=lambda *a: messageShow(self.email.text))
    def press(self,instance):

        name = self.name.text
        password = self.password.text
        if name !="" and password != "":
            self.labelShow.text = "Login......"
            class EchoBot(Client):

                async def on_message(self, mid=None, author_id=None, message_object=None, thread_id=None,
                                     thread_type=ThreadType.USER, at=None, metadata=None, msg=None):
                    await self.mark_as_delivered(thread_id, message_object.uid)
                    await self.mark_as_read(thread_id)


                    # If you're not the author, echo
                    if author_id != self.uid:
                        await self.send(message_object, thread_id=thread_id, thread_type=thread_type)
            loop = asyncio.get_event_loop()

            async def start():
                client = EchoBot(loop=loop)
                #print("Logging in...")

                await client.start(name, password)
                client.listen()
            #
            loop.run_until_complete(start())
            loop.run_forever()
        else:
            self.labelShow.text = "Fail Login Pls Input all information"


        #
        self.labelShow.text = self.email.text


    #name and email must be same in kivy file left


class MyApp(App): # get all method from the import app from the kivy
    def build(self):
        #build is what we gonna put inside the window
        #we put a label inside a window


        return OurGrid() # GET ALL THE INHERIT FROM MY GRID CLASS
        #return Label(text="fafwfwa")


if __name__ =="__main__":
    MyApp().run()#run the class so we get a label











有谁知道我如何将 fbchat-asyncio 等其他软件包包含到手机中的 kivy apk 中?

【问题讨论】:

    标签: python android python-3.x kivy kivy-language


    【解决方案1】:

    认为您遇到的错误与When building an apk for my samsung using buildozer an error occurs 中询问的错误相同

    所以我认为当您阅读日志时,您会收到以下错误:

    ModuleNotFoundError: No module named 'asyncio'
    

    可能的解决方法:

    1. 检查模块是否是纯python,以便可以包含
    2. 检查您是否可以创建一个配方以便部署它
    3. 使用已作为配方提供的模块

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      • 2021-07-19
      相关资源
      最近更新 更多