簡體   English   中英

大家好,我如何在屏幕管理器中播放 kivy 中的視頻我試過但不能

[英]Hello everyone, how do i play video in kivy at screen manager i tried but couldn't

進口:

from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import StringProperty
from kivy.properties import ObjectProperty
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.video import Video
kv = '''

<V>
    BoxLayout:
        spacing: 10
        padding: 20
        orientation: "vertical"
        width: root.width,root.height
        Button:
            text: " [Login-Screen] "
            background_color: (1,1,1,1)
            color: (1,0,0,1)
            bold: True
            font_size: 17
            size_hint: (None,None)
            width: 200
            height: 50
            on_release:
                root.manager.current = "Login"
                root.manager.transition.direction = "up"




<Login>
    ben: benName.text
    pw: passwort.text
    knopf: btn
    knopff: btnn
 
    GridLayout:
        cols: 1
        size: root.width,root.height
        GridLayout:
            cols: 2
            Label:
                text: "Username"
                font_size: 25
            TextInput:
                id: benName
                multiline: False
                font_size: 30
            Label:
                text: "Password"
                font_size: 25
                bold: True
            TextInput:
                password: True
                id: passwort
                multiline: False
                font_size: 40
        Button:
            size_hint: (1.,1.10)
            text:" Start "
            id: btn
            font_size: 40
            on_release:

        Button:
            size_hint: (1.,1.10)
            text: " Exit "
            id: btnn
            font_size: 40
            on_release: app.stop()



'''

我的應用程序MyApp

class Login(Screen):
    ben = StringProperty()
    pw = StringProperty()
    knopf = ObjectProperty()


class MyApp(App):
    Builder.load_string(kv)
 
    def build(self):
        ms = ScreenManager()
        ms.add_widget(V(name='V'))
        ms.add_widget(Login(name='login'))
        self.title = "MyApp"
        return ms




class V(Screen):
    def logo(self):
        video = Video(source='loding_4K.mp4')
        video.state='play'
        video.options = {'eos': 'loop'}
        video.allow_stretch=True
        return video


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

您沒有調用 logo() 方法。 這就是你可以在 kv 文件中更容易做到的方法。

from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import StringProperty
from kivy.properties import ObjectProperty
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.video import Video

kv = '''

<V>
    BoxLayout:
        spacing: 10
        padding: 20
        orientation: "vertical"
        width: root.width,root.height
        Video:
            source: "loding_4K.mp4"
            state: "play"
            options: {'eos': 'loop'}
            allow_stretch: True
        Button:
            text: " [Login-Screen] "
            background_color: (1,1,1,1)
            color: (1,0,0,1)
            bold: True
            font_size: 17
            size_hint: (None,None)
            width: 200
            height: 50
            on_release:
                root.manager.current = "Login"
                root.manager.transition.direction = "up"




<Login>
    ben: benName.text
    pw: passwort.text
    knopf: btn
    knopff: btnn
 
    GridLayout:
        cols: 1
        size: root.width,root.height
        GridLayout:
            cols: 2
            Label:
                text: "Username"
                font_size: 25
            TextInput:
                id: benName
                multiline: False
                font_size: 30
            Label:
                text: "Password"
                font_size: 25
                bold: True
            TextInput:
                password: True
                id: passwort
                multiline: False
                font_size: 40
        Button:
            size_hint: (1.,1.10)
            text:" Start "
            id: btn
            font_size: 40
            on_release:

        Button:
            size_hint: (1.,1.10)
            text: " Exit "
            id: btnn
            font_size: 40
            on_release: app.stop()



'''


class Login(Screen):
    ben = StringProperty()
    pw = StringProperty()
    knopf = ObjectProperty()


class MyApp(App):
    Builder.load_string(kv)
 
    def build(self):
        ms = ScreenManager()
        ms.add_widget(V(name='V'))
        ms.add_widget(Login(name='login'))
        self.title = "MyApp"
        return ms




class V(Screen):
    pass

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

暫無
暫無

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

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