how to chage MDIconbutton color - kivy

Can somebody help me change te color of my MDIconButton.
This is my code.
MDIconButton:
icon: "account"
pos_hint:{"center_x": .95, "center_y": .95}
user_font_size: "35sp"
md_bg_color: app.theme_cls.primary_color
I know it would be a simple problem but i am a starter

According to the documentation, you can use text_color:
theme_text_color: "Custom"
text_color: app.theme_cls.primary_color

Related

Kivy Button macro w get screen instructions

looking to set up a reusable button in my kivy file that includes various root.manager.get_screen instructions under on_press ... Anyone know if this is possible to do in the kv? Thanks so much for any help in advance
<ProductButton#Button>
color: 'black'
outline_color: 'white'
outline_width: 15
on_press:
root.manager.transition.direction = "left"
root.manager.transition.duration = 1
root.manager.current = (root.ids.product1.text+root.ids.label.text+'Detail')
root.manager.get_screen(root.manager.MY_GLOBAL).ids.selection.background_normal = self.background_normal
etc.
The code works in the individual screens but it is long and ugly so I would like to set up a macro instead...
Here is the error I get -
AttributeError: 'ProductButton' object has no attribute 'manager'

Understanding KivyMD Screen Layouts

I want to understand how to layout a KivyMD screen using a GridLayout with ScrollView, and with a BottomNavigation. My code doesn't work because the GridLayout displays over the BottonNavigation which then can't be seen. What is the correct way to setup this layout? And, generally are there rule-of-thumbs for KivyMD screen layouts? Thanks
<MyScreen>:
name: 'myscreen'
ScrollView:
orientation:'vertical'
MDGridLayout:
cols: 3
adaptive_height: True
padding: dp(4), dp(4)
spacing: dp(4)
etc.
BoxLayout:
orientation:'vertical'
MDBottomNavigation:
panel_color: .2, .2, .2, 1
MDBottomNavigationItem:
name: 'left'
text: 'Left'
icon: 'chevron-left'
MDLabel:
text: 'Left'
halign: 'center'
font_style: 'Icon'
MDBottomNavigationItem:
name: 'right'
text: 'Right'
icon: 'chevron-right'
MDLabel:
text: 'Right'
halign: 'center'
font_style: 'Icon'
etc.
The Layout classes monitor the sizes of their children, and recalculates the layout and redraws if that size changes. So, I believe that if your Image size does not change, then only that Image will be updated.
The kivy Builder maintains a set of rules based on the kv files loaded, so whether those rules come from separate files doesn't really matter. I would recommend structuring your kv file(s) based on things like maintainability, readability, and logical partitioning

Toolbar covering the label in kivymd

My MDToolbar is covering the uppermost part of my label, I want the text of my label to appear below the toolbar also the pos_hint is not working on this I want to set the position of my text of label also I want to provide padding on left and right side here's my code in .kv file
<MainScreen>:
BoxLayout:
canvas:
Color:
rgb: 0, 0, 0, 0
Rectangle:
pos: root.pos
size: root.size
ScrollView:
Label:
text:
"""
A boy and a girl were playing together. The boy had a collection of marbles. The girl has some
sweets with her. The boy told the girl that he would give her all his marbles in exchange for the
sweets with her. The girl agreed.
The boy kept the most beautiful and the biggest marbles with him and gave her the remaining marbles.
The girl gave him all her sweets as she promised. That night the girl slept peacefully. But the boy
could not sleep as he kept wondering if the girl has hidden some sweets from him the way he had
hidden the best marbles from her.
Moral of the Story :
If you do not give 100 percent in a relationship, you will always kept doubting if the other person
has given her / his hundred percent. This is applicable for any relationship like love, employee –
employer, friendship, family, countries, etc…
"""
font_size: '20sp'
height: self.texture_size[1]
size: self.texture_size
text_size: root.width, None
size_hint_x: 1.0
size_hint_y: None
halign: "auto"
valign: "middle"
ScreenManager:
id: screen_manager
MainScreen:
name: 'main'
NavigationLayout:
ScreenManager:
Screen:
MDToolbar:
title: "Story"
anchor_title: 'left'
pos_hint: {"top": 1}
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
MDNavigationDrawer:
title: 'Story A Day'
id: nav_drawer
swipe_distance: 10
ContentNavigationDrawer:
id: content_drawer
screen_manager: screen_manager
nav_drawer: nav_drawer
The problem is that your 'kv' file has two rules for building your MainScreen, and both are being executed. You should combine the two rules into one, so that you can refer to different parts of the MainScreen to help in positioning. As an example, adding an id to the MDToolbar allows positioning of the ScrollView below it. Like this:
<MainScreen>:
BoxLayout:
canvas:
Color:
rgb: 0, 0, 0, 0
Rectangle:
pos: root.pos
size: root.size
ScreenManager:
id: screen_manager
MainScreen:
name: 'main'
NavigationLayout:
ScreenManager:
Screen:
MDToolbar:
id: toolbar # id for use below
title: "Story"
anchor_title: 'left'
pos_hint: {"top": 1}
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
ScrollView:
# use toolbar id to position the ScrollView
pos_hint: {'top': 1.0 - toolbar.height / self.parent.height}
Label:
text:
"""
A boy and a girl were playing together. The boy had a collection of marbles. The girl has some
sweets with her. The boy told the girl that he would give her all his marbles in exchange for the
sweets with her. The girl agreed.
.
.
.
Your kv file is overly complicated for what it does. I haven't made any simplifications because you may have reasons for the way you are doing it.

Wrong Kivy widget positions on Surface Pro4

I am relatively new in Kivy. Having studied quite a bit on my laptop, everything works fine until i started working on my surface pro 4. All my buttons were placed in wrong positions, irrespective of how I specify the position, pos or pos_hint, eg:
the window
above is the window that appears when the following code is run:
<Button>:
color: .8, .9, 0, 1
font_size: 31
size_hint: .4, .3
<FloatLayout>
Button:
text: 'button1'
pos_hint: {'x':0, 'top': 1}
Button:
text: 'button2'
pos_hint: {'right': 1, 'y': 0}
could this be due to issues with OpenGL on surface pro 4 or could I have done something totally dumb?
After going through the documentation, I was able to locate the config.ini file on my c: drive and changed the rotation value from 90 to 0. rotation = 0 and my widgets are placed as expected. Kudos to the Kivy.org team, great documentation.

kivy.lang Builder doesn't evaluate simple expressions

While working with kivy.lang Builder I performed some simple arithmetic and it's not working, no error message even.
Builder.load_string ('''
<RootWidget>:
text: 'beautiful Flower Pics '
font_size: 50
Image:
pos: root.pos
size: root.width * 0.5, root.height
source: 'newflower.png'
allow_stretch: True
keep_ration: False
here at root.widht * 0.5 multiplication is not being done. suggestion, hint, advice?
Assuming that RootWidget is a Layout of some sort, you need to set your size_hint. size_hint defaults to 1, 1, and will override your specified sizes. If you set size_hint: None, None then this should size as expected - and depending on the specific type of Layout, you may be able to skip setting size altogether and just use size_hint: 0.5, 1 to get the same effect.

Resources