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
Related
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
I'm trying to make an expense tracker app using KivyMD. I have built it already using kivy but it's design is awful, then i found out KivyMD and now i want to tweak the app using KivyMD but i want to do it without using a kv file because my app has a lot of nested if statements which are too complex to write in the kv file. Anyway, i'm trying to test KivyMD but running into this nasty ValueError
ValueError: KivyMD: App object must be initialized before loading root widget. See https://github.com/kivymd/KivyMD/wiki/Modules-Material-App#exceptions and idk how to fix it without using a kv file. This question is asked plenty times but every answer uses a kv file. Can someone please help me understand this error and tackle it without kv. Thank you... Here is some code
from kivymd.app import MDApp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.app import App
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.stacklayout import MDStackLayout
from kivymd.uix.button import MDRaisedButton, MDRectangleFlatButton
from kivy.metrics import dp,sp
from kivymd.uix.screen import MDScreen
from kivy.uix.textinput import TextInput
from kivymd.uix.textfield import MDTextField
from kivy.uix.screenmanager import ScreenManager
import re
#ALL SCREENS
class MainScreen(MDScreen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
box = MDBoxLayout(orientation="vertical")
b = MDRaisedButton(text="Content",size_hint = (1,0.5))
box.add_widget(b)
t = MDTextField(size_hint=(1,0.5))
box.add_widget(t)
self.add_widget(box)
#ScreenManager
sm = ScreenManager()
sm.add_widget(MainScreen(name="main_screen"))
class MyApp(MDApp):
def build(self):
self.theme_cls.primary_palette = "DeepOrange"
self.theme_cls.accent_palette = "Lime"
return MainScreen()
if __name__ == "__main__":
MyApp().run()
works perfectly fine when i remove the screenmanager and just return the MainScreen.
Any help or guidance is highly appreciated.
I'm using the following code using kivy, trying to load a video. I created a new file that didn't have all the extra things I was doing, as to eliminate all the possible complications. I'm new to stack overflow, so if I've done something wrong don't judge...The video is in the same file, and I've tried everything I found online about these kind of errors, I've also installed pillow and ffpyplayer. The error I receive is [ERROR ] [Image ] Error loading <ironman.mp4>
import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.video import Video
from kivy.uix.videoplayer import VideoPlayer
class MyApp(App):
def build(self):
video = Video(source='ironman.mp4')
video.state = "play"
video.options = {'eos': 'loop'}
video.allow_stretch = True
video.loaded = True
return video
if __name__ == "__main__":
MyApp().run()
I had the same problem but with Image. Install pillow 8.4.0.
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.
Can't understand why I get
AttributeError: 'ColorWheel' object has no attribute 'sv_s'
When I run
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.colorpicker import ColorWheel
from kivy.uix.boxlayout import BoxLayout
class MainApp(App):
def build(self):
box = BoxLayout()
box.add_widget(ColorWheel())
self.root = box
MainApp().run()
and I haven't any errors when use kv, for example:
from kivy.app import App
from kivy.lang import Builder
KV = '''
BoxLayout
ColorWheel
'''
class MainApp(App):
def build(self):
self.root = Builder.load_string(KV)
MainApp().run()
What did I miss?
You missed the warning in the ColorPicker documentation. That is a bug in the ColorWheel code. You should report it as a bug at Kivy Issues.