Refer to Kivy Document page 796, Kivy Most controls use the absolute coordinate system by default, the window coordinate system, where the origin is in the lower-left corner of the screen window, and the coordinates of all controls are the absolute coordinates relative to the lower-left corner of the screen.
Relativelayout uses a relative coordinate system, the relative coordinate system, if relativelayout exists in the control tree, the coordinates origin of the control that belongs to the layout is the lower-left corner of the layout, not the lower-left corner of the screen. If more than one relativelayout is present, the control is the coordinate origin in the lower-left corner of the parent control that is closest to its relativelayout type. If the control itself is also a relativelayout type, but still with the coordinates of the parent control closest to its relativelayout type as the coordinate system, this relative coordinate system is called the parent coordinate system. Conversely, if you are the coordinate system itself, it is the local coordinate system.
Other controls that use relative coordinate systems are scatter, scatterlayout, ScrollView.
Coordinate conversion functions
This kind of function is used to convert window, parent, local coordinates of the three kinds of coordinate system, all receive three parameters, X,y,relative=false (relative parameter function is unknown, I can not test the difference between true and False, ask the big God to inform)
To_widget window coordinates go to local coordinates,
to_local parent coordinates to local coordinates
To_parent local coordinates to parent coordinates
To_window local coordinates go to window coordinates
The following is the test code
#coordinate. KV
1 fromKivy.appImportApp2 fromKivy.uix.boxlayoutImportBoxLayout3 4 5 classMainscreen (boxlayout):6 defbtnright (self,obj):7param =list (Obj.pos)8 param.append (False)9 Print 'Right : {}'. Format (Self.ids.btn2.to_parent (*param))Ten One classTestApp (App): A defBuild (self): - returnMainscreen () - if __name__=="__main__": theTESTAPP (). Run ()
#test. KV
<MainScreen>: Label:text:' Left'Button:text:'Middle'On_touch_down:Print('Middle: {}\n'. Format (args[1].pos)) Relativelayout:on_touch_down:Print('Box: {}'. Format (args[1].pos)) Button:id:btn2 text:' Right'On_touch_down:root.btnright (args[1])
Kivy Learning Path--coordinate system and coordinate transformation function