Kivy类在.py和.kv交互2 [英] Kivy class in .py and .kv interaction 2

查看:725
本文介绍了Kivy类在.py和.kv交互2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

后续 Kivy类在.py和.kv互动,但更复杂。



这里是我写的完整代码:



data / screens / learnkanji_want.kv 想要的代码,但我不完全明白如何 KanjiOriginScreen()扮演它在屏幕管理中的角色。



data / screens / learnkanji.kv 的工作原理,但为了这个工作,我必须把 keyb_height KanjiOriginScreen() main.py )中。但是,我希望代码位于 LayoutFunction() learnkanji.py

问题



如何将 keyb_height c $ c>< LayoutFunction> 文件中的 .kv $ c>



您也可以解释为什么 KanjiOriginScreen:可以放在 learnkanji .kv ,但不包含<



如果有什么不清楚,请问:)



编辑



我发现我没有在learnkanji.kv文件中导入learnkanji.py,导致它无法找到类'LayoutFunction'。

 #:import learnkanji data.screens.learnkanji 


解决方案

对不起,我不清楚我的问题,但在IRC上的帮助#Kivy我结束具体如下:



learnkanji.py



  class LayoutFunctioning BoxLayout):
keyb_height = NumericProperty(260)



learnkanji.kv



  KanjiOriginScreen:
name:'LearnKanji'
全屏:True

LayoutFunction:
id:lfunc
#... code ...
height:lfunc.keyb_height #Instead of root.keyb_height

现在我明白了如何使用id,我可以使用lfunc在LayoutFunction()中调用我的代码:)


Follow up from Kivy class in .py and .kv interaction , but more complex.

Here is the full code of what I'm writing:

The data/screens/learnkanji_want.kv has how I want the code to be, but I don't fully understand how the class KanjiOriginScreen() plays it's role in screen management.

data/screens/learnkanji.kv works how I want it, but for this to work I have to put keyb_height in class KanjiOriginScreen() (main.py). However I want that code to be in the class LayoutFunction() (learnkanji.py).

Question

How can I put keyb_height in the function LayoutFunction() and access this in the .kv file in <LayoutFunction>?

Could you also explain why KanjiOriginScreen: can be put in learnkanji.kv without < > and the program still recognizes it should use this?

If anything is unclear, please ask :)

Edit

I found out that I didn't import the learnkanji.py in the learnkanji.kv file and that caused that it couldn't find the class 'LayoutFunction'.

#:import learnkanji data.screens.learnkanji

解决方案

Sorry I was not clear with my question, but with the help on IRC on #Kivy I ended up with the following:

learnkanji.py

class LayoutFunctioning(BoxLayout):
    keyb_height = NumericProperty(260)

learnkanji.kv

KanjiOriginScreen:
    name: 'LearnKanji'
    fullscreen: True

    LayoutFunction:
        id: lfunc
        #...code...
        height: lfunc.keyb_height #Instead of root.keyb_height

Now I understand how to use the id, I can use lfunc to call my code in LayoutFunction() :)

这篇关于Kivy类在.py和.kv交互2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆