I can’t figure out your code example. I’ll take a few guesses and make some suggestions. Please follow up if I don’t understand.
It is difficult for me to see where you have instanced the class.
In kv when I define a rule
<ColorScreen>: # this defines a rule in kv, this is equivalent to declaring a class in Python.
ColorChangeLayout: # This is an instance of the ColorChangeLayout class. It is a member of the ColorScreen. It will be instanced when the ColorScreen is instanced.
id: color_change_layout_id # I can give this an id
In kv I could instance the ColorScreen under a screenmanger.
BoxLayout: # The root widget
ScreenManger:
id: sm
ColorScreen:
name: ‘color_screen_1’
ColorScreen:
name: ‘color_screen_2’
OtherScreen:
name: ‘another_screen’
The root widget and each kivy rule have their own ids dictionary.
To access the ColorChangeLayout class that is on color_screen_1 from python I would do the following:
class SomeClass(BoxLayout):
def method_to_access_color_change_layout(self):
app = App.get_running_app()
app.root.ids.sm.get_screen(‘color_screen_1).ids.color_change_layout_id.method_of_color_screen()
Breaking this down:
app – is the App class
app.root – is the root widget, a BoxLayout in this example
app.root.ids - the ids dictionary of the root.
app.root.ids.sm –this is the ScreenManager
app.root.ids.sm.get_screen(‘color_screen_1) - This is the instance of the ColorScreen with the name color_screen_1
app.root.ids.sm.get_screen(‘color_screen_1).ids - the ids dict of ColorScreen
app.root.ids.sm.get_screen(‘color_screen_1).ids.color_change_layout_id - This is the instance of ColorChangeLayout on the ColorScreen
app.root.ids.sm.get_screen(‘color_screen_1).ids.color_change_layout_id.method_of_color_screen() # this is how you would access a method of the ColorScreen for this instance.
--
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/191efd03-88b6-4dbf-bdda-f7658957aefbn%40googlegroups.com.
I use a lot of kv, I rarely use the bind method and have not had a need to use fbind directly.
I have internalized that it is faster with limited error checking.
Here are the docs: https://kivy.org/doc/stable/api-kivy.event.html?highlight=fbind#kivy.event.EventDispatcher.fbind
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/8eb78619-4867-4532-bae5-5e8961c3b9aen%40googlegroups.com.
same thing for me , so that means no need to learn it hahahah,
I am have an issue with MDTextfield, its pos_hint_y always changing when parent height changes, how can I make it fixable at a certain level!
I don’t know about the specifics of MDTextfield, but in general to fix a size of a widget you must set the size_hint to None.
To fix size:
size_hint: None, None
To fix height:
size_hint_y: None
height: 200
To fix width:
size_hint_x: None
width: 200
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/11045410-ad35-44b2-ae32-57e1a7e329f5n%40googlegroups.com.
Take a look at the source:
https://github.com/kivymd/KivyMD/blob/master/kivymd/uix/textfield.py
What layout are you using?
You are seeing the position change. How are you specifying the position?
The size of the graphics in MDTextField are sized dynamically.
Use the inspector to get a better idea of what is going on…
python mymain.py -m inspector
Then press control-e, and select MDTextField, and examine the properties.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/45120bca-df90-4938-a129-6bfa27f4e822n%40googlegroups.com.