基维,鼠标周围不透明,露出图片



我想做一个谜题,有人必须跟着迷宫走,收集信件,这些信件必须在以后输入作为答案。(不是由程序收集,只是记住传递的字母,然后在退出迷宫时输入)

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.config import Config
Config.set('graphics', 'width', '806')
Config.set('graphics', 'height', '706')
class Touch(Widget):
def __init__(self, **kwargs):
super(Touch, self).__init__(**kwargs)
def on_touch_down(self, touch):
pass
def on_touch_down(self, touch):
pass
def on_touch_down(self, touch):
pass

class MyGrid(GridLayout):
pass

class DrawingWindow(App):
def build(self):
return MyGrid()
if __name__ == "__main__":
DrawingWindow().run()
<MyGrid>:

GridLayout:
cols:1
size:1000,706
canvas:

Rectangle:
size: 808,706
source: 'Puzzle.png'

我已经知道如何画一个圆圈,你的鼠标是(没有添加到代码,因为我认为一个不同的方法可能会被使用),但如何使周围的一切一定半径黑色,使它只显示这个半径内的一个小圆。也许在半径范围内使用不透明度是一个解决方案。如果有人能给我指出正确的方向,那就太好了。

它不必保持暴露,而不是实际上。希望这也能让它更简单一些。

我希望我已经说清楚了问题所在。提前感谢您的时间和精力。

您可以使用模板指令来完成此操作。下面是一个简单的例子:

from kivy.app import App
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.properties import NumericProperty, ListProperty
from kivy.uix.widget import Widget
kv = '''
RelativeLayout:
ImageWithHole:
id: hole
canvas:
StencilPush
Ellipse:  # draw the hole
pos: self.hole_pos[0] - self.radius, self.hole_pos[1] - self.radius
size: self.radius*2, self.radius*2
StencilUse
Color:
rgba: 1,1,1,1
Rectangle:
source: 'Puzzle.png'  # draw the maze
pos: 0,0
size: self.size
StencilUnUse
Ellipse:  # erase the hole (must be identical to original draw above)
pos: self.hole_pos[0] - self.radius, self.hole_pos[1] - self.radius
size: self.radius*2, self.radius*2
StencilPop
'''

class ImageWithHole(Widget):
radius = NumericProperty(50)
hole_pos = ListProperty([400, 300])

class TestApp(App):
def build(self):
Window.bind(mouse_pos=self.on_motion)
return Builder.load_string(kv)
def on_motion(self, src, mouse_pos):
hole = self.root.ids.hole
hole.hole_pos = mouse_pos
TestApp().run()

最新更新