答案 0 :(得分:1)
将第一层/布局的opacity
设置为0.5
不透明
小部件及其所有子级的不透明度。
opacity属性控制小部件及其控件的不透明度 孩子们。请注意,这是一个累积属性:值是 乘以当前的全局不透明度,结果应用于 当前的上下文颜色。
...
opacity是NumericProperty,默认值为1.0。
点:列表
点列表,格式为(x1,y1,x2,y2…)
获取/设置直线点的属性
警告
这将始终从新点重建整个图形 清单。这可能是非常昂贵的CPU。
圆圈
使用此属性可以构建一个圆,而无需计算点。 您只能设置此属性,而不能获取它。
该参数必须是(center_x,center_y,radius, angle_start,angle_end,线段):
- center_x和center_y代表圆心
- 半径代表圆的半径
- (可选)angle_start和angle_end以度为单位。默认值为0和360。
- (可选)线段是椭圆的精度。默认值是根据角度之间的范围计算的。
请注意,是否闭合圆圈取决于您。
from kivy.base import runTouchApp
from kivy.core.window import Window
from kivy.uix.screenmanager import Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.graphics import Color, Line
from kivy.metrics import dp
Window.clearcolor = (1, 1, 1, 1)
class Overlay2Layouts(Screen):
def __init__(self, **kwargs):
super(Overlay2Layouts, self).__init__(**kwargs)
self.size = Window.size
layout1 = BoxLayout(opacity=0.5)
with layout1.canvas:
Color(1, 0, 0, 1) # red colour
Line(points=[self.center_x, self.height / 4, self.center_x, self.height * 3/4], width=dp(2))
Line(points=[self.width * 3/ 4, self.center_y, self.width /4, self.center_y], width=dp(2))
layout2 = BoxLayout()
with layout2.canvas:
Color(0, 0, 0, 1) # black colour
Line(circle=[self.center_x, self.center_y, 190], width=dp(2))
self.add_widget(layout1)
self.add_widget(layout2)
if __name__ == "__main__":
runTouchApp(Overlay2Layouts())
from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.core.window import Window
Window.clearcolor = (1, 1, 1, 1)
runTouchApp(Builder.load_string('''
#:kivy 1.11.0
Screen:
BoxLayout:
opacity: 0.5
canvas.before:
Color:
rgba: 1, 0, 0, 1
Line:
width: dp(2.)
points: [self.center_x, self.height / 4, self.center_x, self.height * 3/4]
Line:
width: dp(2.)
points: [root.width * 3/ 4, self.center_y, root.width /4, self.center_y]
BoxLayout:
canvas.before:
Color:
rgba: 1, 0, 0, 1
Line:
width: dp(2.)
circle: (root.center_x, root.center_y, 190)
'''))
答案 1 :(得分:0)
为了补充python中的答案,当窗口更改大小时,覆盖层没有调整大小,因此这是我的解决方案:
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.graphics import Color, Line, Ellipse, Rectangle
from kivy.metrics import dp
class RootWidget(BoxLayout):
def __init__(self, *args, **kwargs):
BoxLayout.__init__(self, *args, **kwargs)
self.bind(pos=self.draw)
self.bind(size=self.draw)
self.layout1 = BoxLayout(opacity=0.3)
self.layout2 = BoxLayout()
self.add_widget(self.layout1)
self.add_widget(self.layout2)
def draw(self, *args):
with self.canvas.before:
Color(1,1,.5,1)
self.bg = Rectangle(pos=self.pos, size=self.size)
self.layout1.canvas.clear()
with self.layout1.canvas:
Color(1, 0, 0, 1) # red colour
Line(points=[self.center_x, self.height / 4, self.center_x, self.height * 3/4], width=dp(2))
Line(points=[self.width * 3/ 4, self.center_y, self.width /4, self.center_y], width=dp(2))
self.layout2.canvas.clear()
with self.layout2.canvas:
Color(0, 0, 0, 1) # black colour
Line(circle=[self.center_x, self.center_y, 190], width=dp(2))
class Overlays_3(App):
title = "Overlays_3"
def build(self):
return RootWidget()
if __name__ == "__main__":
Overlays_3().run()