Unable to change kivy icon - python

I'm trying to change icon from kivy default one to some ico/png file that i provide
But it seems to be not working
I get this
Code:
from kivymd.app import MDApp
from kivy.lang import Builder
KV="""
Button:
text:""
"""
class Main(MDApp):
def build (self):
self.icon="image.png"
return Builder.load_string(KV)
Main().run()
Update:
Fixed the problem by changing the png,
But it still shows kivy logo for the loading screen ,is there any fix for this.???

Related

Kivy: Change popup title label proprieties

I'm writing an interface with Kivy.
I've added a change in my .kv file that remove size_hint from Label
<Label>
size_hint: None, None
This change reflects itself obviously on all labels, included the labels of all buttons and, my problem, the label of the popup title.
In fact, label of the popup title remains little and text goes to newline after few letters (you can see it easily by creating a popup with a long title and set the Label with size_hint: None, None)
I could write a custom class like MyLabel#Label but this will not reflects on all buttons, and I should rewrite all buttons, and all place where labels are used but not explicitly declared by the code.
That's why I'm looking for another way to accomplish this.
There's a way to tell to kivy, in .kv file or in my python main.py, to use a different label class for my popup title? or to set the size_hint property of the label used in the popup title?
Thanks for Your Attention,
Best Regards.
[EDIT]
Screenshot of the running example problem
Example:
my.kv
<Label>
size_hint: None, None
main.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.core.window import Window
def ForceLimit():
pop = Popup(title='Force limit reached!',content=Label(text='Force limit reached! Decremental movement inhibited.'),size_hint=(None, None), size=(400, 400))
pop.open()
kv = Builder.load_file("my.kv")
class MyMainApp(App):
def build(self):
#Window.borderless = True
Window.size = (1024,600)
return ForceLimit()
if __name__ == "__main__":
MyMainApp().run()

KivyMD without using kv file

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.

VScode kivy wont use the .Kv file

I'm using VScode and Kivy. I cant seem to get Kivy to read the .kv file. I have both the .py file and .kv files set up, but when I run the program all I get is an empty box.
.kv file:
#kivy 2.0.0
<layout>
Label:
text: 'text here'
.py file:
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
class layout(GridLayout):
pass
class theApp(App):
def build(self):
return layout()
if __name__ == "__main__":
theApp().run()
I can get it all to work if I write it in just the .py file but nothing works from the .kv file.
If I under stand right the box should say "text here".

AttributeError: 'Snackbar' object has no attribute 'show'

I'm making a desktop app using kivymd and i need to show a simple Snackbar on a button click that just lets the user know that the process went smoothly, but no matter what i try to do i get the error message: AttributeError: 'Snackbar' object has no attribute 'show'.
I installed kivy and kivymd correctly, i know this because i already made an app without using Snackbars. Hope you can help me, here's the code:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.snackbar import Snackbar
KV = '''
BoxLayout:
MDRaisedButton:
text: "click"
on_press: app.test_bar()
'''
class TestApp(MDApp):
def build(self):
return Builder.load_string(KV)
def test_bar(self):
Snackbar(text="Hello world!").show()
TestApp().run()
Snackbar(text="Hello world!").open()

Loading one line of text from file to Kivy label

I want to make a simple program that is just showing definitions that are stored in text file.One label and button to show next definition. I try to do it with documentation but i cannot find how to load text into label. Can someone show me to some good resources or code samples ?
My code for now (i want to build in on top of example from kivy website):
import kivy
kivy.require('1.9.0')
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()
The easiest way to update widgets in the UI are by binding to their properties. This can be done in code, but the real power of kivy in my opinion comes from using it's declarative UI language. Using kv, you get automatic binding.
Here is a quick example of what you might do:
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import StringProperty
kv = '''
BoxLayout:
orientation: 'vertical'
Label:
text: app.text
Button:
text: 'click me'
on_press: app.clicked()
'''
class MyApp(App):
text = StringProperty("hello world")
def build(self):
return Builder.load_string(kv)
def clicked(self):
self.text = "clicked!"
if __name__ == '__main__':
MyApp().run()
In the kv description of the UI, you tell kivy that you want the text on the Label to be bound to a StringProperty on the app which you defined on the class. The auto-binding means that anytime you set a value to that property (like in the clicked function), the UI will update with the new value automatically.

Categories