Я изучаю KIVY из "Kivy: Интерактивные приложения в Python", и я пытался интегрировать AnchorLayout, ScrollView и RelativeLayout в соответствии с примером кода, приведенным ниже.
В коде, который я дал ниже Я пытался визуализировать «RelativeLayout» в ScrollView (в anchorlayout anchor_x: 'center' и anchor_y: 'center'), определяя размер прямоугольника self.size. Кажется, что прямоугольник рисуется поверх "ToolBox", который находится в AnchorLayout: anchor_x: 'center' и anchor_y: 'top'. Согласно моему KV холст должен быть точно между "ToolBox" и "GeneralOptions". Но почему это совпадение.
#File name: comiccreator.kv
<ComicCreator>:
AnchorLayout:
anchor_x: 'center'
anchor_y: 'top'
ToolBox:
id : _tool_box
size_hint: 1,None
height: 20
orientation: 'horizontal'
Label:
text: 'Tool Box'
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
ScrollView:
size_hint: 1,1
RelativeLayout:
size_hint: 1,None
height: root.height - _tool_box.height - _general_options.height
canvas.before:
Color:
rgba: 1,0,0,0.5
Rectangle:
size: self.size
pos: self.pos
DrawingSpace:
id: drawing_space
Label:
text: 'DrawingSpace'
pos : 0, 50
size: 50, 50
AnchorLayout:
anchor_x: 'center'
anchor_y: 'bottom'
GeneralOptions:
id: _general_options
size_hint: 1,None
height: 20
orientation: 'horizontal'
Label:
text: 'General Options'
Сценарий python это ...
# File name: comiccreator.py
import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.core.window import Window
class DrawingSpace(RelativeLayout):
pass
class ToolBox(BoxLayout):
pass
class GeneralOptions(BoxLayout):
pass
class ComicCreator(AnchorLayout):
pass
class ComicCreatorApp(App):
def build(self):
return ComicCreator()
if __name__=="__main__":
Window.size = (400, 200)
ComicCreatorApp().run()