i am trying to create a video splash screen but when i play the video only only is played and screen is blank. The video format is mp4. Also can you help me change the to a different screen after the video ends
How do i go about it?
from kivy import *
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.clock import Clock
from kivy.uix.videoplayer import VideoPlayer
import time
from ffpyplayer import *
# audio
import os
from playsound import playsound
import threading
class SplashScreen(Screen):
# def on_enter(self, *args):
# Clock.schedule_once(self.switch_to_home, 5)
# splash_video()
def switch_to_home(self, dt):
self.manager.current = "home"
def splash_video():
video = VideoPlayer(source = '/home/devesh/Desktop/readzy-app/images/logo(watermark).mp4')
video.state = 'play'
video.options = {'eos': 'switch_to_home()'}
return video
splash_video()
home_page = Builder.load_file("Readzy.kv")
# ! main app class
class Readzy(App):
def build(self):
sm = ScreenManager()
sm.add_widget(SplashScreen(name='splash'))
sm.add_widget(HomeScreen(name='home'))
sm.add_widget(ReadingScreen(name='reading'))
sm.add_widget(WPSScreen(name="wps"))
return sm
# run the app
if __name__ == "__main__":
Readzy().run()```
I hv tried mpeg format but the result is same
Related
I want to print('hello') after running the m.run() but IDLE just shows me the result of m.run and it does not print the hello. How can I print a string after m.run()?
This is an example of my problem:
import socket
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
class me (App):
def __init__(self):
super().__init__()
self.b=Button(text='button')
self.g=GridLayout(cols=4)
self.l=Label(text='label')
self.t=TextInput(text='Type here your message: ')
self.g.add_widget(self.b)
self.g.add_widget(self.t)
self.g.add_widget(self.l)
def build(self):
return self.g
m=me()
m.run()
print('hello')
i try to write Persian in python kivy but it is not working.
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.lang import Builder
from kivy import Config
from kivy.uix.label import Label
from kivy.uix.widget import Widget
class MainApp(App):
def build(self):
return Label(text= "فارسی")
if __name__ == "__main__":
MainApp().run()
You need to use some Persian font.
I have done it with Arabic text
You can download the font from here
Then use arabic_reshaper library to get it in shape.
pip install arabic-reshaper
You will also need python-bidi as well to flip the letters
pip install python-bidi
Refer to this https://github.com/mpcabd/python-arabic-reshaper
Code
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.lang import Builder
from kivy import Config
from kivy.uix.label import Label
from kivy.uix.widget import Widget
import arabic_reshaper
from bidi.algorithm import get_display
class MainApp(App):
def build(self):
reshaped_text = arabic_reshaper.reshape("فارسی")
bidi_text = get_display(reshaped_text)
return Label(text= bidi_text, font_name='Amiri-Regular.ttf', font_size=30)
if __name__ == "__main__":
MainApp().run()
Output
Kivy is not loading an image for me, its showing '[image][error] error reading file x.png'
My python code (in short) is:
from kivy.core.window import Window
from kivy.properties import NumericProperty
from kivy.properties import ObjectProperty
from kivy.properties import StringProperty
from kivy.uix.floatlayout import FloatLayout
from kivymd.app import MDApp
from kivymd.theming import ThemeManager
from kivymd.uix.snackbar import Snackbar
import requests
class Home(FloatLayout):
pass
class MainApp(MDApp):
def __init__(self,**kwargs):
super().__init__(**kwargs)
self.theme_cls = ThemeManager()
self.theme_cls.theme_style = "Light"
self.theme_cls.primary_palette = ('LightBlue')
Window.size = (400,600)
Kivy file (again part that matters) is:
MDBottomNavigation:
MDBottomNavigationItem:
text:'Home'
name: 'Home'
Home:
Image:
source:'khatam.png'
Image:
source: 'togeather.png'
I have pip installed Kivy with all its dependencies(including GStreamer) and have OpenCV. Also, I am using Pycharm. The rest of the code is working just fine only this part is bugged.
I am relatively new. Thanks in advance.
I'm using Kivy for a user interface to a control application. As such, the UI is subsidiary to the essential functionality. For modularity/tidyness, I've been trying to place all the Kivy code in a separate source file and to call it as the last step in Main.
However, if I do this, I find that some things don't work properly (for example, creating labels programatically and updating their text by scheduled events).
Is this something which should be possible?
Is there a 'trick' of which I should be aware?
If the detail of my question is not clear, I can put up some test code to illustrate.
Monolithic code, which works as expected:
cat test.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.properties import StringProperty
from kivy.clock import Clock
import random
Builder.load_string('''
<YourWidget>:
BoxLayout:
id: Box1
size: root.size
Button:
id: button1
text: "Change text"
on_release: root.change_text()
''')
class YourWidget(Screen):
random_number = StringProperty()
def __init__(self, **kwargs):
super(YourWidget, self).__init__(**kwargs)
label = Label(
id= 'label1',
text = self.random_number
)
self.ids.Box1.add_widget(label)
self.random_number = 'ini'
Clock.schedule_interval(self.change_text,1)
def change_text(self, *largs):
self.random_number = str(random.randint(1, 100))
class updatetestapp(App):
def build(self):
sm = ScreenManager(transition=NoTransition())
sm.add_widget(YourWidget(name='d_analogs'))
return YourWidget()
if (True):
updatetestapp().run()
If I then attempt to modularise my code, placing all the Kivy processing in a user function,everything works except the display of the ransom number variable. The variable persists through successive callbacks, as shown by calls to print, but it simply doesn't display. I'm guessing that this is something to do with the scope or context of the variable - Kivy isn't displaying the same variable which is being updated in the callback.
cat Main.py
#from mytest import mytest
import threading
import time
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.properties import StringProperty
from kivy.clock import Clock
from display import *
def main():
Display()
if __name__ == "__main__":
main()
cat display.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.properties import StringProperty
from kivy.clock import Clock
import random
Builder.load_string('''
<YourWidget>:
BoxLayout:
id: Box1
size: root.size
Button:
id: button1
text: "Change text"
on_release: root.change_text()
''')
class YourWidget(Screen):
random_number = StringProperty()
def __init__(self, **kwargs):
super(YourWidget, self).__init__(**kwargs)
label = Label(
id= 'label1',
text = self.random_number
)
self.ids.Box1.add_widget(label)
self.random_number = 'ini'
Clock.schedule_interval(self.change_text,1)
def change_text(self, *largs):
self.random_number = str(random.randint(1, 100))
class test(App):
def build(self):
sm = ScreenManager(transition=NoTransition())
sm.add_widget(YourWidget(name='d_analogs'))
return YourWidget()
def Display():
test().run()
You don't have any code that would change the text of your Label. Although you update self.random_number, you don't update the Label's text property, therefore you don't see any change.
this is my script ...
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.image import Image
class MyApp(App):
def build(self):
return Image(source='go.jpg')
MyApp().run()
I won't to reload it becose the image is changing and I won't to see the new won all time
you can use reload() the read the image from the disk again
this will reload even if the original data of the image is updated or changed
self.ids.image1.source = './Images/file.png'
self.ids.image1.reload()
Make your own widget class, and make the image an attribute, so you can reference it. Then use clock to schedule an interval method, to constantly reload the image.
In the example below, the update_pic method is executed once every second.
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.image import Image
from kivy.clock import Clock
from kivy.uix.widget import Widget
class MyImageWidget(Widget):
def __init__(self,**kwargs):
super(MyImageWidget,self).__init__(**kwargs)
self.image = Image(source='go.jpg')
self.add_widget(self.image)
Clock.schedule_interval(self.update_pic,1)
def update_pic(self,dt):
self.image.reload()
class MyApp(App):
def build(self):
return MyImageWidget()
MyApp().run()
You can use the Image.reload method
def build(self):
img = Image(source='go.jpg')
Clock.schedule_interval(lambda dt: img.reload(), 0.2) #5 per second
return img