为了账号安全,请及时绑定邮箱和手机立即绑定

AttributeError: 'kivy.graphics.context_instruc

AttributeError: 'kivy.graphics.context_instruc

一只名叫tom的猫 2023-05-23 15:33:29
以下代码有什么问题?# Program to Show how to create a switch# import kivy moduleimport kivy# base Class of your App inherits from the App class.# app:always refers to the instance of your applicationfrom kivy.app import App# this restrict the kivy version i.e# below this kivy version you cannot# use the app or softwarekivy.require('1.9.0')# Builder is used when .kv file is# to be used in .py filefrom kivy.lang import Builder# The screen manager is a widget# dedicated to managing multiple screens for your application.from kivy.uix.screenmanager import ScreenManager, Screen# You can create your kv code in the Python fileBuilder.load_string(""" <ScreenOne>:     BoxLayout:         canvas.before:        Color:            rgba: (.4, .6, 9, 1)                          #(0,0,0,1)        Rectangle:            size: self.size            pos: self.pos        canvas:            Color:                rgba: (1, 1, 1,1)            RoundedRectangle:                size : self.width/2, self.height/3                pos : self.center_x - self.width/4 , self.center_y - self.height/6                                         radius: [(40, 40), (40, 40), (40, 40), (40, 40)]                       Button:             text: "Go to Screen 2"             background_color : 0, 0, 1, 1             on_press:                 # You can define the duration of the change                 # and the direction of the slide                 root.manager.transition.direction = 'left'                 root.manager.transition.duration = 1                 root.manager.current = 'screen_two' 我是 kivy 的新手,在网上获得了这段代码,效果很好。我现在试图通过在其中放置一些画布和形状来更改它,但出现错误: AttributeError: 'kivy.graphics.context_instructions.Color' object has no attribute 'fbind'这是什么意思,我怎样才能再次改变它以实现我的目标,即放置我的 2 个矩形并在它们上面放置按钮?
查看完整描述

1 回答

?
LEATH

TA贡献1936条经验 获得超6个赞

假设您正确复制并粘贴了代码,但缩进是错误的,您已将 Color 指令放在子小部件级别,而不是缩进到canvas.before:. 这很可能导致您的错误。



查看完整回答
反对 回复 2023-05-23
  • 1 回答
  • 0 关注
  • 73 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信