簡體   English   中英

在 python/kivy 中使用 screenmananger 時出現黑屏

[英]Getting a black screen when using screenmananger in python/kivy

我正在嘗試使用 kivy 和 python 構建一個應用程序。 當我實現屏幕管理器時,我得到了一個黑屏。 正如您在我的代碼中看到的,我有兩個屏幕:ApppScreen 和 AllitemsScreen。 我想讓我的 ApppScreen 首先作為“主屏幕”出現。 出了什么問題? 提前致謝!

kv文件:

<ApppScreen>:
    Label:
        text: 'hoi'
    BoxLayout:
        size: root.width, root.height
        orientation: 'vertical'
        Label:
            text: 'hey'
            size_hint: 1, .1
        ScrollView:
            size_hint: 1, .3
            GridLayout:
                size_hint: 1,None
                height: self.minimum_height
                cols: 1
                MyLabel:
                    text: ' items'
                GridLayout:
                    id: container
                    cols: 2
                    size_hint_y: None
                    height: self.minimum_height
                    row_force_default: True
                    row_default_height: dp(260)

        TextInput:
            title: 'NewItem'
            id: input
            multiline: False
            size_hint: 1, .1

        Button: 
            text: 'add new item'
            size_hint: 1, .1
            on_press: app.add_a_row()

        Button:
            text: 'All items'
            size_hint: 1, .1
            on_press: root.manager.current = 'allitems'

<AllitemsScreen>:
    BoxLayout:
        size: root.width, root.height
        orientation: 'vertical'
        Label:
            text: 'hey'
            size_hint: 1, .1
        ScrollView:
            size_hint: 1, .3
            GridLayout:
                size_hint: 1,None
                height: self.minimum_height
                cols: 1
                MyLabel:
                    text: 'All items'
                GridLayout:
                    size_hint: 1,None
                    height: self.minimum_height
                    cols: 2
                    rows: 25                
                    MyLabel: 
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel: 
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel: 
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel: 
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel: 
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel: 
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
        TextInput:
            title: 'NewItem'
            id: input
            multiline: False
            size_hint: 1, .1

        Button: 
            text: 'add new item'
            size_hint: 1, .1
            on_press: root.newitem(input.text)
        Button:
            text: 'items2'
            size_hint: 1, .1
            on_press: root.manager.current = 'appp'


<TextInp>:

    title: 'NewItem'
    id: test1
    auto_dismiss: False

    TextInput: 
        multiline: False
        id: input
        hint_text:'Enter the items url'
        on_text: app.NewItem() 

<Row>:
    orientation: "horizontal"

    Image:
        source: app.image_source
        width: 100

main.py 文件

import kivy
kivy.require('1.9.0')

from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.uix import image
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget

from price import ExtractPrice
from pythonmain import Item
from image import ExtractImage

import requests
from urllib.request import urlopen
from PIL import Image
from datetime import date

class ApppScreen(Screen):
    def newitem(self, link):
        item_list.append(Item(link))
        print(item_list[0].store, item_list[0].original_price)

class AllitemsScreen(Screen):
    pass


sm = ScreenManager()

sm.add_widget(ApppScreen(name='appp'))
sm.add_widget(AllitemsScreen(name='allitems'))

class Row(BoxLayout):
    pass

class notifier(App):

    image_source = item1.image
    print(image_source)

    def build(self):
        return sm

    def add_a_row(self):
        self.root.ids.container.add_widget(Row())


if __name__ == '__main__':
    notifier().run()

在加載 kv 之前創建小部件。 而是在 build 方法中創建它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM