I am developing a mobile application. There should be a picture in the introduction of my application. Even though I put the picture and show the way, the picture does not appear when I run the application. It is replaced by a white screen. How can I solve it?
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.image import Image
from kivy.animation import Animation, AnimationTransition
class loginImage(Image):
pass
class loginScreen(App):
def build(self):
img = Image()
return img
loginScreen().run()
My .kv code in here:
<-loginScreen>:
source: 'images.jpeg'
kv rules are for widgets, not the App class, so your source isn't applied to anything.
Set the source of the Image widget that you return.
Related
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.
Im working on a basic app using python and kivy and im trying to import an image which I'm basically going to use as a splash screen of sorts but for some reason I couldn't get it to work so I created a .py file and wrote some very simple code to try to get it to work:
from kivy.app import App
from kivy.uix.label import Label
from kivy.core.window import Window
Window.size = (360, 640)
class ImageTestApp(App):
def build(self):
label = Label(source="image.jpg")
return label
if __name__ == "__main__":
ImageTestApp().run()
The image is in the same directory of the .py file and the name of the image is exactly the same, I even made the window size the same as the image size and tried .PNG but nothing worked 😖
Label does not have an attribute called source. You should change Label to Image, and it will works. Please refer to example below for details.
Example
main.py
from kivy.app import App
from kivy.uix.image import Image
from kivy.core.window import Window
Window.size = (360, 640)
class ImageTestApp(App):
def build(self):
return Image(source="image.jpg")
if __name__ == "__main__":
ImageTestApp().run()
Output
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
I don't like the default gradient background for the unfocused TextInput so I edited the default texture in Paint. But it doesn't seem to recognize it. It's in a separate file and looks like this:
The texture I get is just plain white. Do I need a specific file with the texture or to move the texture to the place where it is in the default texture?
This is a test code:
from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
class App1(App):
def build(self):
b = BoxLayout()
tx1 = TextInput()
tx = TextInput(background_normal = "E:\textinput_unfocused.png")
b.add_widget(tx1)
b.add_widget(tx)
return b
App1().run()
Oh, by the way. The source code is located in the E: disk, as well as the textinput_unfocused.png.
the path for Your background should be specified relative to the app file. So if they are both in the same directory just put:
tx = TextInput(background_normal = "textinput_unfocused.png")
I'm trying to write a very basic Kivy program that will have an image popup if the right user input is given. I had one image I'm using to test with, but I keep getting the error
"pygame.error: couldn't load cattemp.jpg"
The image is in the same directory as the file, so I know that's not the issue.
Here's what the code looks like:
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.core.image import Image
def test():
popup = Popup(title='Test popup',
content=Image('cattemp.jpg').texture,
size_hint=(None, None), size=(400, 400))
Any help would be hugely appreciated.
Thank you!
You can only load PNG.
Use PIL to convert the file or use another.
Create your image with something like:
import PIL
im = PIL.Image.open('cattemp.jpg')
im.save('cattemp.png')
Then you use the image in your program
content=Image('cattemp.png').texture,
...
Can't load doesn't necessarily mean it's not found.