【问题标题】:beeware adding toga imageview to androidbeeware将toga imageview添加到android
【发布时间】:2021-04-12 06:33:55
【问题描述】:

我正在用 beeware 构建小型 android 项目。最近发现 beeware toga GUI 工具包不支持 android 中的图像/imageview 是否有任何调整或其他方法可以用来在我的 android 项目中添加图像。我找到了一个叫做 toga-android 但没有指南。任何帮助都会对我很有帮助,谢谢。
这是我的小代码 sn-p。

"""
Time Table app for salah 
"""
import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW

class drd(toga.App):

    
    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """
        
        self.main_box = toga.Box(style=Pack(direction=COLUMN))

        self.l_username = toga.TextInput(placeholder='User name',style=Pack(flex=1))
        self.l_password = toga.TextInput(placeholder='Password',style=Pack(flex=1))
        
        self.checkbutton = toga.Button('Log in',on_press=self.login_btn,style=Pack(padding=5))
        
        self.label_box = toga.Box(style=Pack(direction=ROW,padding=5))
        self.main_box.add(self.label_box)
        self.label_box.add(self.l_username)
        self.main_box.add(self.l_password)
        self.main_box.add(self.checkbutton)
        
        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = self.main_box
        self.main_window.show()
        
    def signup_btn(self,button):
        self.main_window.info_dialog("hi there","Hello {}".format(self.name_input.value))

    def login_btn(self,button):
        if self.l_username.value == "Imtiyaz" and self.l_password.value == "123":
            self.home()

        else:
            self.main_window.info_dialog("User name or Password is incorrect!")
            self.home()

    def home(self):
        self.main_box = toga.Box(style=Pack(direction=COLUMN, background_color='#7ed6c6'))
        self.hello = toga.Label('Hello there!')
        self.img = toga.ImageView(id='images',image='./resources/drd.png')
        self.main_box.add(self.hello)
        self.main_box.add(self.img)
        self.main_window = toga.MainWindow(title="app")
        self.main_window.content = self.main_box
        self.main_window.show()

def main():
    return drd()

【问题讨论】:

    标签: android python-3.x beeware


    【解决方案1】:

    我可以使用 this 列表成功启动我正在使用 BeeWare/Toga 在模拟器和 amazon-HD-10 平板电脑上(重新)构建的早期测试应用程序进口量:

    import toga
    from toga import App, Box, MainWindow
    from toga import ImageView, Image
    from toga.style import Pack
    from toga.style.pack import COLUMN, ROW, BOTTOM, TOP, LEFT
    import sys                 # <==  that one's just to exit() the app...
    

    也许您忘记了重要的导入?

    下图左侧有2张公文包的SDK模拟器重叠图片。
    (为了使 ImageViews “可点击”,我必须使用一个尚未合并到 Toga 中的拉取请求分支 - 并且可能永远不会......)

    (这是关于 Toga 的 ImageView 的 link to my github discussion。右侧较小的图片来自 JS 版本,最初是为 Sony-PRS 500 电子书阅读器制作的,16 种灰色)

    。 . . Youtube video of advanced WORKING APP in emulator

     ===============================================
    

    【讨论】:

      猜你喜欢
      • 2021-11-04
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多