Black-screen after loading python code?

120 views
Skip to first unread message

Damacia Cyril

unread,
Sep 11, 2018, 3:42:38 AM9/11/18
to Kivy users support
I'm running a photo-booth project with python 2.7.9 and by kivy software built may I know why everytime after Press run it doesn't displayed anything but just a black-screen and I need to reboot again else it will just stucked in the Black-screen of death. Anyone can help??Thanks


Coding:
from __future__ import print_function
import os, time, sys
import Image

import kivy
kivy.require('1.11.0')

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image as kivyImage
from kivy.clock import Clock
from kivy.graphics import Color, Rectangle

# Some variables
photoPath = "/home/pi/Desktop/CameraP/NewImage.jpg"
photoName = time.strftime("%Y%m%d%H%M%S") + "_NewImage.jpg"
photoResize = 512, 384
photoTitle = "Kiehl's Photo Booth!"

# Callback function for photo button
def photo_callback(obj):
# Define filename with timestamp
        photoName = time.strftime("%Y%m%d%H%M%S") + "_NewImage.jpg"
# Take photo using "raspistill"
        os.system("sudo raspistill -p '144,48,512,384' --vflip -w 800 -h 600 -o " + photoPath + photoName)
# Resize the high res photo to create thumbnail
        Image.open(photoPath + photoName).resize(photoResize,Image.ANTIALIAS).save(photoPath + "thumbnail.jpg")


class MyApp(App):
# Display the latest thumbnail
        photo = kivyImage(source="/home/pi/Desktop/CameraP/thumbnail.jpg")
def build(self):
# Set up the layout
                photobox = GridLayout(cols=3, spacing=10, padding=10)
# Create the UI objects (and bind them to callbacks, if necessary)
                photoButton = Button(text="photo", size_hint=(.20, 1)) # Button: 5% width, 100% height
                photoButton.bind(on_press=photo_callback) # when pressed, trigger the photo_callback function
                
# Periodically refresh the displayed photo using the callback function
                Clock.schedule_interval(self.callback, 1)
# Add the UI elements to the layout
                photobox.add_widget(photoButton)
                photobox.add_widget(self.photo)

                return photobox
        
# Callback for thumbnail refresh
def callback(self, instance): 
         self.photo.reload()
         
if __name__ == '__main__':
        MyApp().run()        

ZenCODE

unread,
Sep 11, 2018, 3:28:57 PM9/11/18
to Kivy users support
Well, the callback fired when you press the button (photo_callback) does not create a new image or put it anywhere you can see it. It does not even create a new Image, it just calls a method on the Image class definition. But that's not going to show you anything.

I would suggest starting with a more simple app. Work through the tutorials, lean about instancing, how to create images and pop them in and out of your user interface. Once you know how to do that, return to you original project.

ooiz...@gmail.com

unread,
Sep 11, 2018, 9:38:12 PM9/11/18
to Kivy users support
then what should I add to my original programming please help I'm new to python.Can you help me to rewrite my programme or change anything into it which make it works?

ZenCODE

unread,
Sep 12, 2018, 4:32:11 PM9/12/18
to Kivy users support
Hi

Below works and displays stuff. Hope that helps you get started. Good luck :-)


# from__future__import print_function
import os, time, sys

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image
from kivy.clock import Clock
from kivy.uix.label import Label


# Some variables
photoPath = "/home/pi/Desktop/CameraP/NewImage.jpg"
photoName = time.strftime("%Y%m%d%H%M%S") + "_NewImage.jpg"
photoResize = 512, 384
photoTitle = "Kiehl's Photo Booth!"




class MyApp(App):
# Display the latest thumbnail


    # Callback function for photo button
    def photo_callback(self, *args):

# Define filename with timestamp
photoName = time.strftime("%Y%m%d%H%M%S") + "_NewImage.jpg"
# Take photo using "raspistill"
        # os.system(
# "sudo raspistill -p '144,48,512,384' --vflip -w 800 -h 600 -o " + photoPath + photoName)
        # Resize the high res photo to create thumbnail
        # Image.open(photoPath + photoName).resize(photoResize,
# Image.ANTIALIAS).save(
# photoPath + "thumbnail.jpg")
self.photobox.clear_widgets()
self.photobox.add_widget(Label(text="New stuff added this way"))



def build(self):
# Set up the layout
photobox = GridLayout(cols=3, spacing=10, padding=10)
# Create the UI objects (and bind them to callbacks, if necessary)
photoButton = Button(text="photo",
size_hint=(.20, 1)) # Button: 5% width, 100% height
photoButton.bind(
            on_press=self.photo_callback)  # when pressed, trigger the photo_callback function

# Periodically refresh the displayed photo using the callback function
        Clock.schedule_interval(self.photo_callback, 1)

# Add the UI elements to the layout
photobox.add_widget(photoButton)
        photo = Image(source="/home/pi/Desktop/CameraP/thumbnail.jpg")
photobox.add_widget(photo)

self.photobox = photobox
return photobox

ooiz...@gmail.com

unread,
Sep 12, 2018, 8:17:07 PM9/12/18
to Kivy users support
Hi Thanks for the help ya! Well how do I add UI and camera into this code??

ooiz...@gmail.com

unread,
Sep 12, 2018, 11:12:24 PM9/12/18
to Kivy users support
I wanted to build a project exactly like this can you help me out what I followed his code is I just get a black screen: 


On Thursday, September 13, 2018 at 4:32:11 AM UTC+8, ZenCODE wrote:

ZenCODE

unread,
Sep 14, 2018, 2:17:09 AM9/14/18
to Kivy users support
I'm afraid you'll have to try that yourself. I'm here to help, but I can't afford the time to do it for you. You need to try and learn the skills to do it yourself. There are lots's of tutorials and you can try. But start with small steps. The camera is quite and advanced stage, so I would get to grips with the basics first....
Reply all
Reply to author
Forward
0 new messages