android - 使用 kivy - kivy 启动器在 android 上查看打印语句的输出

标签 android python kivy

我创建了一个程序,它在运行时在 stdoutput 上打印一些指令。当我在 Windows 上执行应用程序时,我可以看到它们,但是当我在安卓设备三星 S3 上运行相同的应用程序时,我无法在任何地方看到打印语句的输出。

有时我们可以在设备上看到 .kivy 目录与程序在同一目录中,但这些日志文件也包含 kivy 特定日志,但它们忽略打印语句输出。

任何人都可以就如何使用它给出一些建议......

最佳答案

使用 adb logcat获取您的应用程序的输出,或使用在线可用的应用程序之一来帮助显示您的日志和 grep 以获取“Python”。

上面的详细步骤::

在您的设备上启用开发者选项(谷歌是您的 friend )。 然后启用USB 调试

enter image description here 图片取自 http://androidfannetwork.com/

然后使用 USB 电缆将您的设备连接到您的电脑,然后在您的控制台中键入 adb devices。 它应该会显示您的设备(可能会提示您提供连接到计算机的权限)。

一种更简单的方法是在小部件上使用视觉指示而不是在控制台上打印。 你可以为你的应用创建一个函数 bubprint

from kivy.core.window import Window
from kivy.clock import Clock
from kivy.factory import Factory
from kivy.lang import Builder

Builder.load_string('''
<InfoBubble@Bubble>
    # declare our message StringProperty
    message: 'empty message'
    # let the bubble be of 200 device pixels
    # and expand as necessary on the height
    # depending on the message + 20 dp of padding.
    size_hint: None, None
    show_arrow: False
    pos_hint: {'top': 1, 'right': 1}
    size: dp(200), lbl.texture_size[1] + dp(20)
    Label:
        id: lbl
        text: root.message
        # constraint the text to be displayed within
        # the bubble width and have it be unrestricted
        # on the height.
        text_size: root.width - dp(20), None
''')

def bubbprint(self, message):
    message = repr(message)
    if not self.info_bubble:
        self.info_bubble = Factory.InfoBubble()
    self.info_bubble.message = message

    # Check if bubble is not already on screen
    if not self.info_bubble.parent:
        Window.add_widget(self.info_bubble)

    # Remove bubble after 2 secs
    Clock.schedule_once(lambda dt:
        Window.remove_widget(self.info_bubble), 2)

关于android - 使用 kivy - kivy 启动器在 android 上查看打印语句的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23055696/

相关文章:

python - urllib2.urlopen 的真实签名是什么

python - 如何从自定义神经网络模型中获取对数和概率

python - 导出单个 .exe 时,PyInstaller 卡在 "Building PKG ..."上

python - 名称错误 : Factory name not defined - Kivy

android - 如何在相对于android中的设备的特定位置调整对话框的位置

android - Xamarin.Android 项目无法在适用于 Android 的 Visual Studio 模拟器中部署

python - 在 Python Google App Engine 中,如何模拟或子类化 File 类,以便编写用于访问文件的软件不会抛出异常?

python - Kivy相机在多个屏幕上

android - 将服务部署到 Google Play

java - android中的计算器多操作数