我想在画布上画出无限多的形状,所以我决定用滚动视图来完成。但是,当我添加一个滚动视图时,画布上不会出现任何形状。你知道吗
副本:
# draws the shape
def draw_streak(self, obj):
name = obj.id
with open("streak.json", "r") as file:
read = json.load(file)
for key in read.keys():
if key == name:
with open("streak.json", "r+") as f:
data = json.load(f)
get_score = data.get(key, {}).get('score')
can = self.root.get_screen("three")
new_pos = can.pos
for x in range(-1, get_score): # had to use -1 to get correct amount of shapes
with can.ids.my_box.canvas:
Color(0, 1, 0, .75, mode='rgba')
rect = Rectangle(pos=new_pos, size=(30,30))
new_pos[0] += rect.size[1]
new_pos[0] += rect.size[0]
千伏:
<ScreenThree>
id: screen_three
name: "three"
on_leave: my_box.canvas.clear()
on_leave: selected_streak.canvas.clear()
on_leave: del_space.canvas.clear()
GridLayout:
cols: 1
rows: 2
GridLayout:
cols: 3
rows: 1
AnchorLayout:
anchor_x: "left"
anchor_y: "top"
Button:
text: "Back"
size: 50, 25
size_hint: None, None
font_size: 18
on_release: app.root.current = "two"
AnchorLayout:
id: selected_streak
anchor_x: "center"
anchor_y: "top"
AnchorLayout:
id: del_space
anchor_x: "right"
anchor_y: "top"
ScrollView:
do_scroll_x: False
do_scroll_y: True
GridLayout:
cols: 1
id: my_box
size_hint_y: None
height: self.minimum_height
row_force_default: True
row_default_height: 50
另外,更改x大小提示是否会使不适合的形状在屏幕上向下移动?你知道吗
编辑
在特定时间按下按钮时称为“绘制条纹”。你知道吗
...
elif delay > time.time() > self.honey: # on time (green)
child.background_normal = ''
child.background_color = [0, 1, 0, .95]
child.unbind(on_press=self.early_click)
child.bind(on_press=self.add_score)
child.bind(on_press=self.display_streak)
child.bind(on_press=self.draw_streak)
child.unbind(on_press=self.late_click)
json值的键score
与按钮id同名
编辑
截图
问题3
解决方案
从左到右和从上到下(lr-tb)方向绘制矩形。你知道吗
片段
输出-演示
问题2
解决方案
with can.canvas:
替换with can.ids.my_box.canvas:
片段
输出
在ScrollView中的按钮上绘制形状
get_cell()
以获取my_box
内按钮的实例片段
输出
相关问题 更多 >
编程相关推荐