How to Click on icon_right inside MDTextField

679 views
Skip to first unread message

Anoop Rana

unread,
Apr 8, 2020, 9:46:25 AM4/8/20
to kivy-...@googlegroups.com
Hi i am using a MDTextField that has an icon at the right corner .How can i click on it and do something like call a function?Following is the code:

MDTextField:
    hint_text: "Name"
    icon_right: "arrow-down-drop-circle-outline"
    icon_right_color: app.theme_cls.primary_color

I know i can use MDDropDownMenu to click on a button to choose from a list of options.
Is there a way to Click on that arrow icon at the right corner of the textfiled and
choose from a list of options?Lke it should expand and show some options to choose from and
the user can press on any option. 

Screenshot from 2020-04-08 19-05-18.png

Robert Flatt

unread,
Apr 8, 2020, 1:25:36 PM4/8/20
to Kivy users support
Yep, the documentation of actions is KivyMD is limited ! Missing when it should be there, so impossible to know if it should be there  :(

All I can tell you is how I answer my own questions like this , read the KivyMD source
Sorry but that is all I got. I looked at your question ....

Looking in here it appears this is an MDIcon

And an MDIcon is a MDLabel

So I'd say there would be no action associated with a Label.
But I suggest you do this for yourself because maybe I missed something.

Anoop Rana

unread,
Apr 8, 2020, 3:54:03 PM4/8/20
to kivy-...@googlegroups.com
Yeah you are correct documentations on actions still lack a little .But that's ok considering the progress kivymd is making in the last few months.Also do you know how can one add a gradient (color gradient) to a button.For example as we use md_bg_color to set the color of the background so is there  a way to add a gradient instead?.Maybe i can create a gradient in some editor and then add it.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d2a4a1de-98cd-4c20-a8be-d0a9c8373524%40googlegroups.com.

Elliot Garbus

unread,
Apr 8, 2020, 6:02:05 PM4/8/20
to kivy-...@googlegroups.com

Here is a color gradient…  I found this code in  a google search, and updated it to python 3, I’m embarrassed that I did not credit the original author.

 

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle
from kivy.graphics.texture import Texture


class MyWidget(Widget):
   
def __init__(self, **args):
       
super(MyWidget, self).__init__(**args)

       
self.texture = Texture.create(size=(2, 1), colorfmt='rgb')

        color1 =
0
       
color2 = 255

       
buf = ''.join(map(chr, [color1, color2])).encode('utf-8')

       
self.texture.blit_buffer(buf)

       
with self.canvas:
            Rectangle(
pos=self.pos, size=self.size, texture=self.texture)


class TestGApp(App):
   
def build(self):
       
return MyWidget(size=(200, 200))


if __name__ == '__main__':
    TestGApp().run()

Elliot Garbus

unread,
Apr 8, 2020, 6:08:46 PM4/8/20
to kivy-...@googlegroups.com

Here is a link with what looks like more flexible code, and link to the original code from Tshirtman!

Anoop Rana

unread,
Apr 9, 2020, 12:30:17 AM4/9/20
to kivy-...@googlegroups.com
Ok so if let's say i have created a custom gradient in an editor then how can i set that as a button's md_bg_color?

MDRaisedButton:
      text:'Gradient Button'
      size_hint:[.2,.1]
      md_bg_color:utils.get_color_from_hex('#474547')
And what else should i add/do to use the gradient created in any other editor to be set as this button's md_bg_color?Maybe add source:'file.png' or else?


Elliot Garbus

unread,
Apr 9, 2020, 12:38:55 AM4/9/20
to kivy-...@googlegroups.com

Take a look at the source or the docs.  They must have a button image they are associating with the editor.

Is MDRaisedButton derived from Button (That would be my expectation)…

 

Take a look at the kivy docs for button.  You will find there are 4 properties images. 

 

background_down, background_normal

background_disabled_down, background_disabled_normal.

https://kivy.org/doc/stable/api-kivy.uix.button.html?highlight=button#module-kivy.uix.button

Anoop Rana

unread,
Apr 9, 2020, 12:54:46 AM4/9/20
to kivy-...@googlegroups.com
Ok so i looked and background_down, background_normal are working with Button but not with MDRaisedButton.I will create a custom button with elevation and all ....Thanks.Also i also checked buttons.py inside kivymd/uix.

Elliot Garbus

unread,
Apr 9, 2020, 12:56:29 AM4/9/20
to kivy-...@googlegroups.com

Look for a kv file that the MD package is using… I’d expect to find what you are looking for in the kv file.

Elliot Garbus

unread,
Apr 9, 2020, 1:23:37 AM4/9/20
to kivy-...@googlegroups.com

I couldn’t help myself.  I took a look at the kivymd code.  The kv is in buttons.py.  Enjoy.

Robert Flatt

unread,
Apr 9, 2020, 2:38:54 AM4/9/20
to Kivy users support
KivyMD buttons are where KivyMD is very different from Kivy.
KivyMD buttons inherit from kivy ButtonBehavior not kivy Button.
It doesn't seem one can change the image (but can the color), its just not the MD way.
I fought this kind of thing for a while, till I finally figured out how to follow the MD approach and it looks good.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Anoop Rana

unread,
Apr 9, 2020, 2:47:32 AM4/9/20
to kivy-...@googlegroups.com
Yes correct.Like MDRaisedButton inherits from BaseButton,....and so on but not from Button.And if we try to add Button as an argument in MDRaisedButton(BaseButton,......,Button) it gives an error related to self.filename.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f5b88435-a616-4a40-a88e-79e83f433c1f%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages