in KivyMD there is a module or something called "Boxshadow", I need it to use almost every widget which uses levitation and i couldn't find anything resolving this issue. I am just a beginner with Kivy and KivyMD especially therefore I would be truly thankful for a solution. I as well cant follow simple tutorials because something does not work for me which works for them.
The simplest Application:
from kivymd.app import MDApp
from kivymd.uix.screen import MDScreen
from kivymd.uix.button import MDRectangleFlatButton
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.config import Config
import kivy
from kivy.core.window import Window
Window.size = (200, 425)
class MainApp(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "DeepPurple"
return Builder.load_file('Mainapplication.kv')
MainApp().run()
Kivy:
MDScreen:
MDRaisedButton:
text: "Knopf"
pos_hint: { "center_x": 0.5, "center_y": 0.8}
ERROR Raised:
File "C:\KivyMD\virtual\lib\site-packages\kivy\factory.py", line 147, in __getattr__
raise FactoryException('Unknown class <%s>' % name)
kivy.factory.FactoryException: Unknown class <BoxShadow>
Related
I'm trying to create a simple login page for this app using Kivy.
I'm new to this, and I'm wondering how I can connect the Email TextInput to a variable (email_catch) in my python code, similar to a normal .get() function.
Python Code
from kivy.app import App
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty, StringProperty
class Login_Window(Screen):
def verify(self):
email_catch = self.root.ids.email.text
print(email_catch)
class MyApp(App):
def build(self):
return Login_Window()
if __name__ == "__main__":
MyApp().run()
.KV File
#:kivy 2.0.0
<Login_Window>:
GridLayout:
cols:1
size: root.width, root.height
GridLayout:
cols:2
Label:
text: 'Email'
TextInput:
multiline: False
id: email
Button:
text: 'Log In'
on_press: root.verify()
Since you are calling root in verify method of Login_Window class (where it (root) hasn't been defined yet) and not in the build method of the App class you are supposed to get an AttributeError .
In order to access an id within that class you should use self.ids. So the change you need:
def verify(self):
email_catch = self.ids.email.text
print(email_catch)
When I use screenmanager nothing displayed om my screen kivymd python
I don't get any error so that means no bug in my code, but it doesn't display anything, and anyone of the both screens
this is my code :
from kivymd.app import MDApp
from kivy.uix.widget import Widget
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
from kivymd.uix.toolbar import MDToolbar
from kivymd.uix.button import MDFlatButton, MDRectangleFlatButton, MDIconButton, MDFloatingActionButton
from kivymd.uix.label import MDLabel, MDIcon
class firstscreen(Screen):
pass
class secondscreen(Screen):
pass
class windowmanager(ScreenManager):
pass
kv = Builder.load_file('sc.kv')
class Yom(MDApp):
def build(self):
return kv
if __name__ == '__main__':
Yom().run()
and this is the sc.kv file
windowmanager:
firstscreen:
secondscreen:
<firstscreen>:
name:'firstscreen'
MDRectangleFlatButton:
text:"calc moy"
pos_hint:{'center_x':0.5,'center_y':0.5}
on_release:MDApp.root.current='secondscreen'
<secondscreen>:
name:'secondscreen'
MDLabel:
text:'welcome to calcu screen'
halign:'center'
The issue was, that you did not capitalize the first letter of your classes. Kivy is very picky about this and refuses to load the screen correctly when you don't do this.
On a side note:
Classes should always be capitalized and use PascalCase as per PEP 8
Corrected Code:
main.kv:
WindowManager:
FirstScreen:
secondscreen:
<FirstScreen>:
name:'firstscreen'
MDRectangleFlatButton:
text:"calc moy"
pos_hint:{'center_x':0.5,'center_y':0.5}
on_release:MDApp.root.current='secondscreen'
<SecondScreen>:
name:'secondscreen'
MDLabel:
text:'welcome to calcu screen'
halign:'center'
main.py:
from kivymd.app import MDApp
from kivy.uix.widget import Widget
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
from kivymd.uix.toolbar import MDToolbar
from kivymd.uix.button import MDFlatButton, MDRectangleFlatButton, MDIconButton, MDFloatingActionButton
from kivymd.uix.label import MDLabel, MDIcon
class FirstScreen(Screen):
pass
class SecondScreen(Screen):
pass
class WindowManager(ScreenManager):
pass
class Yom(MDApp):
def build(self):
kv = Builder.load_file('main.kv')
return kv
if __name__ == '__main__':
Yom().run()
Kivy is not loading an image for me, its showing '[image][error] error reading file x.png'
My python code (in short) is:
from kivy.core.window import Window
from kivy.properties import NumericProperty
from kivy.properties import ObjectProperty
from kivy.properties import StringProperty
from kivy.uix.floatlayout import FloatLayout
from kivymd.app import MDApp
from kivymd.theming import ThemeManager
from kivymd.uix.snackbar import Snackbar
import requests
class Home(FloatLayout):
pass
class MainApp(MDApp):
def __init__(self,**kwargs):
super().__init__(**kwargs)
self.theme_cls = ThemeManager()
self.theme_cls.theme_style = "Light"
self.theme_cls.primary_palette = ('LightBlue')
Window.size = (400,600)
Kivy file (again part that matters) is:
MDBottomNavigation:
MDBottomNavigationItem:
text:'Home'
name: 'Home'
Home:
Image:
source:'khatam.png'
Image:
source: 'togeather.png'
I have pip installed Kivy with all its dependencies(including GStreamer) and have OpenCV. Also, I am using Pycharm. The rest of the code is working just fine only this part is bugged.
I am relatively new. Thanks in advance.
I am attempting to construct a screen with a VERTICAL splitter to separate content; however, I am unsuccessful in identifying a solution even after consulting the kivy docs and looking through the related questions here.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.splitter import Splitter
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.properties import StringProperty, DictProperty
from kivy.uix.screenmanager import ScreenManager, Screen
kv = '''
ScreenManagement:
id: 'manager'
MainScreen:
name: 'main'
manager: 'manager'
<MainScreen>:
BoxLayout:
orientation: 'vertical'
Button:
text: 'New'
Splitter:
sizeable_from: 'top'
Button:
text: 'test'
'''
class ScreenManagement(ScreenManager):
pass
class MainScreen(Screen):
pass
class MyApp(App):
def build(self):
return Builder.load_string(kv)
MyApp().run()
Here is what I am current seeing with this code
As you can see, the splitter is beside the second button rather than between the buttons horizontally; and when the splitter is activated, it shrinks the button horizontally rather than vertically. How do I change the code for the effect that I desire?
Simple misspelling. sizeable_from should be sizable_from.
I'm trying to setup a day and month display.
In the planner.kv file I can't get the Telldate child widget to work with pos_hint in FloatLayout but it seems to be working fine with Button.
I'm not sure if i've set up FloatLayout properly or if I'm going about it in the wrong way.
I understand that Telldate is a custom widget and a child widget when inside FloatLayout unless I'm wrong about that.
Everything else is working as intended
main.py
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from time import strftime
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
class Telldate(Widget):
todayday = ObjectProperty('')
def __init__(self,*args, **kwargs):
super().__init__(*args, **kwargs)
self.todayday= strftime('%A')
class PlannerApp(App):
pass
if __name__ == '__main__':
PlannerApp().run()
planner.kv
<Telldate>:
Button:
size:(50,50)
text:self.parent.todayday
FloatLayout:
Button:
text: 'ay'
size_hint:(None,None)
pos_hint: { 'x': 0.5, 'y': 0.8}
Telldate:
size_hint:(None,None)
pos_hint: { 'x': 0.5, 'y': 0.8}
I'm using python V3.6.2 and Kivy v1.10.0 with IDLE V3.6.2
Thanks for your patience!
----Edit1:---
using
class Telldate(FloatLayout):
instead of
class Telldate(Widget):
allows me to set hint_size because i'm now inheriting FloatLayout properties and not widget properties but still doesn't allow hint_pos to be set.
The rest of the code is still the same.
So what I learnt was that widgets don't inherit properties of layouts which is where my troubles began with Telldate(Widget), i found this in the documentations for widget.
Using Telldate(FloatLayout) instead and calling(not sure if the right terminology) the class Telldate via <Telldate> into kivy solved my issue.
And then creating FloatLayout for whenever I want to call a custom widget as in the .kv file
planner.kv
<Tellday#Label>:
size:(50,50)
<Telldate>:
FloatLayout:
Tellday:
size_hint:( None,None)
text: self.parent.parent.todayday
pos_hint:{'top': 0.5,'right':0.5}
main.py
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from time import strftime
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.lang import Builder
class Telldate(FloatLayout):
todayday= ObjectProperty('')
# todaymonth = ObjectProperty('')
def __init__(self,*args, **kwargs):
super().__init__(*args, **kwargs)
self.todayday=strftime('%A')
self.todayday= strftime('%A')
# self.todaymonth= strftime('%b')
class PlannerApp(App):
def build(self):
return Telldate()
if __name__ == '__main__':
PlannerApp().run()
hope this helps someone!