# Kivy Learning Path--coordinate system and coordinate transformation function

Source: Internet
Author: User

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

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.