TypeError: on_current_bg() takes 1 positional argument but 3 were given

17 views
Skip to first unread message

Glen Rubin

unread,
Jan 25, 2023, 12:50:42 PM1/25/23
to Kivy users support
Hi Friends!

I'm having issues with and on_ type property method.  

I have a string property called current_bg and want to implement on_current_bg so that some functions are called whenever current_bg is updated.  When my program runs I get the error in the subject line:

 TypeError: on_current_bg() takes 1 positional argument but 3 were given


Here is a minimal version of my program:

from kivy.uix.screenmanager import Screen
from kivy.properties import StringProperty, ListProperty, NumericProperty

class SweetLight(Screen):
    #property list
    current_bg = StringProperty('')
    label_color = ListProperty([0, 0, 0, 1])
    R = NumericProperty(0)
    G = NumericProperty(0)
    B = NumericProperty(0)
    A = NumericProperty(1)

    def on_pre_enter(self):
        self.current_bg = self.manager.current_bg

    def on_current_bg(self):
        self.RGB(int(self.current_bg))

    def RGB(self, bg):
        self.bg2R(bg)
        self.bg2G(bg)
        self.bg2B(bg)

    def bg2R(self, bg):
        R=2
        self.R = R
        self.label_color[0] = R / 255.0

    def bg2G(self, bg):
        G= 100
        self.G = G
        self.label_color[1] = G / 255.0

    def bg2B(self, bg):
        B=155
        self.B = B
        self.label_color[2] = B / 255.0

Elliot Garbus

unread,
Jan 25, 2023, 2:37:43 PM1/25/23
to kivy-...@googlegroups.com

See: https://kivy.org/doc/stable/api-kivy.properties.html?highlight=properties#observe-using-on-propname

When the kivy property changes  self, instance and value are passed to the event handler.

 

The python convention is the use CapWords for classes and snake_case for methods.  You might want to change the method RGB to rgb

See: https://pep8.org/#class-names

 

Im not sure what you are trying to do – but you might find some of the utils helpful:  https://kivy.org/doc/stable/api-kivy.utils.html?highlight=utils#kivy.utils.rgba

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/be33cb2d-20f0-4158-aaf8-ec456771509fn%40googlegroups.com.

 

Glen Rubin

unread,
Jan 25, 2023, 4:10:57 PM1/25/23
to kivy-...@googlegroups.com
awesome, thanks for the tip!  I might be able to use that util to shrink my code :D

You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/GgIYEjRxmBA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63d18500.810a0220.c2cc.262aSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Reply all
Reply to author
Forward
0 new messages