import kivy
from kivy.app import App
from kivy.uix.label import Label
class Simplekivy(App):
def build(self):
return Label(text="salam")
if __name__ == "__main__":
Simplekivy().run()
this is what i get
"
[CRITICAL] [App ] Unable to get a Window, abort.
"
import kivy
from kivy.app import App
from kivy.uix.label import Label
class Simplekivy(App):
def build(self):
return Label(text="aleykum salam")
if __name__ == "__main__":
Simplekivy().run()
This code works; your installation/dependencies must be at fault.
Please give us more to see what may be the issue.
Related
I'm working in simple kivy app for android that play sound every minute, i want to make it work in background even when I close app
from kivy.app import App
from kivy.uix.button import Button
from kivy.core.audio import SoundLoader
import time
class MyApp(App):
def build(self):
self.sound = SoundLoader.load('1.wav')
start_but = Button(text='start',
on_press = self.click
)
return start_but
def click(self, obj):
while True:
self.sound.play()
time.sleep(60)
if __name__ == '__main__':
MyApp().run()
I tried to make the kivy window only restart after that i exit the window but i still can't find a way , any ideas ?
import sys
import kivy, os
from kivy.app import App
from kivy.uix.label import Label
from kivy.clock import Clock
class MyApp(App):
def build(self):
Clock.schedule_once(self.restart, 10)
return Label(text='Hello World One!')
def restart(self, dt):
os.execv(sys.executable, [sys.executable] + sys.argv)
if __name__ == '__main__':
MyApp().run()
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 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 am trying to close the kivy window automatically without pressing any button after a specific amount of time.
Code:
class Tester(App):
def build(self):
return Label(text="Hi")
if __name__ == '__main__':
Tester().run()
Thank you!
You can use Clock to invoke the stop method of the application:
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.label import Label
class Tester(App):
def build(self):
Clock.schedule_once(self.stop, 5)
return Label(text="Hi")
if __name__ == "__main__":
Tester().run()
You can also use App().get_running_app().stop() with the Clock to close the kivy window:
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.label import Label
class Tester(App):
def build(self):
return Label(text="Hi")
Clock.schedule_once(App().get_running_app().stop, 1)
if __name__ == "__main__":
Tester().run()