Kivy returns "Unable to find any valuable Window provider" - kivy

I have installed all dependencies from kivyOfficial website and I got no error but when I run the program
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello world')
if __name__ == '__main__':
MyApp().run()
I get this error:

Related

Why does Kivy say Unresolved reference 'Myapp'?

import kivy
from kivy.app import App
from kivy.uix.label import Label
class Myapp(App):
def build(self):
return Label(text="hey")
if __name__ == "__main__":
Myapp().run()
Why does Kivy say Unresolved reference 'Myapp' here?
from kivy.app import App
from kivy.uix.label import Label
class Myapp(App):
def build(self):
return Label(text="hey")
if __name__ == "__main__":
Myapp().run()
Try this, if statement isn't part of the class so it shouldn't be idented
This is what helped
In PyCharmm in the Project Interpreter, add all the packages that start with:
kivy-deps.
With the exclusion of the ones with "dev" in the title
Looks like you have a ModuleNotFoundError for PIL. Try installing PIL through:
pip3 install Pillow

Is a Kivy app using Pulp compatible with Android?

I am trying to create a Kivy app which involves linear optimization using Pulp. The app works fine on my laptop but when I deploy on my Android Phone using buildozer, it fails to load (even if I just import Pulp modules and not actually use them). I include Pulp in the spec file and don't get any error while deploying.
Example - This app fails to load on Andriod but when I remove pulp imports it works -
from kivymd.app import MDApp
from kivymd.uix.screen import Screen
from pulp import LpMaximize, LpProblem, LpStatus, lpSum, LpVariable, LpSolverDefault
from kivymd.uix.label import MDLabel, MDIcon
from kivymd.font_definitions import theme_font_styles
from kivy.uix.widget import Widget
class DemoApp(MDApp):
def build(self):
screen = Screen()
label = MDLabel(text="check", halign="center", theme_text_color="Error",
font_style="Subtitle2", pos_hint={'center_x': 0.4, 'center_y': 0.9}, id = "test")
screen. add_widget(label)
return screen
DemoApp().run()
Does this mean Pulp is not compatible with Kivy or am I doing something wrong?

How to add a clock widget to a screen?

I'm trying to make a GUI and I want a clock like this:
https://github.com/dwalker0044/KivyDigitalClock
I want to add it to a menu page that has buttons to navigate to other pages but I can't figure it out. I imported the file but I can't figure out how to add it to the screen. I've been having trouble with this for a while so if someone could help me out.
Here is my code:
main.py
from kivy.config import Config
Config.set('kivy', 'keyboard_mode', 'systemanddock')
#KivyTest.py
import kivy
kivy.require('1.0.6') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.properties import ObjectProperty
from kivy.clock import Clock
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
#from cefpython3 import cefpython as cef
from glob import glob
from random import randint
from os.path import join, dirname
from kivy.app import App
from kivy.logger import Logger
from kivy.uix.scatter import Scatter
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage
from kivy.uix.scrollview import ScrollView
from kivy.properties import StringProperty
import sys
import platform
import webbrowser
import random
import os
import time
import datetime
from kivy.app import App
from kivy.clock import Clock
from kivy.properties import StringProperty
from kivy.properties import NumericProperty
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.graphics import *
from digitalclock import DigitalClock
from digitalclock import SecondsIndicator
class Face(Screen):
pass
class Menu(Screen):
def open_Browser(self):
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
cef.Initialize()
cef.CreateBrowserSync(url="https://www.google.com/",
window_title="Google")
cef.MessageLoop()
cef.Shutdown()
def open_YouTube(self):
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
cef.Initialize()
cef.CreateBrowserSync(url="https://www.youtube.com/",
window_title="YouTube")
cef.MessageLoop()
cef.Shutdown()
def open_Pictures(self):
picturesApp = PicturesApp()
picturesApp.run()
def open_Camera(self):
TestCamera().run()
class Commands(Screen):
pass
class Manager(ScreenManager):
face = ObjectProperty(None)
menu = ObjectProperty(None)
class IonApp(App):
def build(self):
m = ScreenManager(transition = NoTransition())
m.add_widget(DigitalClock(name='Clock'))
return m
if __name__ == '__main__':
IonApp().run()
The add_widget() method of a ScreenManager only accepts Screen instances.
You should be getting an error when you try to add a DigitalClock instance to your ScreenManager.
You need to add the DigitalClock instance to one of your Screen objects (like your Menu or your Commands) and then add that Screen to your ScreenManager using add_widget().
The KivyDigitalClock code is not well prepared for inclusion into others code. Assuming that you have placed the digital clock code in a digitalclock folder (as it appears from your code), then you will also need a Builder.load_file('digitalclock/digitalclock.kv') call in your code. A good place for this would be just before your IonApp().run() call.
So here is what I think would work:
class IonApp(App):
def build(self):
m = ScreenManager(transition = NoTransition())
screen = Commands(name='commands')
dc = DigitalClock()
screen.add_widget(dc)
m.add_widget(screen)
dc.update()
return m
if __name__ == '__main__':
Builder.load_file('digitalclock/digitalclock.kv')
IonApp().run()

kivy+gspread crashes while trying in an android phone, but works fine in my laptop

I am using gspread and oauth2client in a very simple kivy app, I just want to update one cell in my google sheet. The code works just fine in my PC but when I build the apk file using buildozer and upload it to my android phone it crashes. Is there any conflict between gspread and kivy ???? The code is shown below;
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('cl_sec.json', scope)
client = gspread.authorize(creds)
sheet = client.open('project2').sheet1
class bxlayout(BoxLayout):
def __init__(self, **kwargs):
super(bxlayout, self).__init__(**kwargs)
btn1 = Button(text='ON')
btn1.bind(on_press=self.clk1)
self.add_widget(btn1)
btn2 = Button(text='OFF')
btn2.bind(on_press=self.clk2)
self.add_widget(btn2)
def clk1(self, obj):
self.background_color = [0,0,1,1]
sheet.update_cell(2,1, '1')
self.background_color = [1,1,1,1]
def clk2(self, obj):
self.background_color = [0,0,1,1]
sheet.update_cell(2,1, '0')
self.background_color = [1,1,1,1]
class appfile(App):
def build(self):
ml = bxlayout()
return ml
if __name__ == "__main__":
appfile().run()
Without logcat any question like this pretty much tells nothing about the problem because:
the code obviously works (laptop)
the packaging apparently too (you can install and launch the app)
so as Eugene suggested, the problem is most likely with you not including the package either in the buildozer's .spec file - the important part looks like this:
requirements = kivy
and for you to use a third-party library you have to mention its name in that particular line:
requirements = kivy,gspread
or with similar python-for-android console switch.
Depending on if it's pure-python or C-extension it will or will not throw an error during packaging now. If it's an extension, you need to write a recipe for it.

Kivy OSC Windows

Thanks for your quick answer laltin. The code lines are here in the .py file.
kivy 1.9.0
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.lang import Builder
from simpleOSC import initOSCClient, initOSCServer, closeOSC, \
setOSCHandler, sendOSCMsg
class OscShowcase(BoxLayout):
pass
class TestOscApp(App):
def build(self):
return OscShowcase()
def send_Osc(self, *l):
sendOSCMsg('activate', [3.0])
#pass
if name == 'main':
host = '127.0.0.1'
sport = 9000
rport = 9001
# osc
initOSCClient(host, sport)
initOSCServer(host, rport)
TestOscApp().run()
.kv file
:
BoxLayout:
Widget:
Button:
text: 'OSC'
pos: (500, 400)
on_press: app.send_Osc()
sendOSCMsg: ('/%s/press', [])
#on_release: app.send_Osc()
#sendOSCMsg: ('activate', [3.0])
Do you think I can edit the OSC messages directly in the kv.file in order to separate every button with its assigned osc message? This is my main issue from the beginning. In fact i would like to control one of my Max patches on 3 systems, Ipad, MacbookPro and pc at the same time with the OSC protocol. And Kivy is the best on this I think. I already have a graphic plan of what I designed mostly in kv. langage. I can share the code with you if you don't mind. Thanks again for your big help.
stkflwrglator
The line on_press: do_root_action() in your .kv file means that when user presses the button the function do_root_action will be called. But do_root_action is not defined in your application.
Add send_Osc method to your app:
class TestOscApp(App):
...
def send_Osc(self, *l):
sendOSCMsg('/chaine_en_dur/', [2.0])
Call send_Osc method on button press
Button:
text: 'OSC'
pos: (500, 500)
on_press: app.send_Osc()

Resources