Invalid Syntax for Assignment in Kivy File

1k views Asked by At

I've got a KV file that describes a simple popup with a few sliders that are supposed to change the R, G and B values of a color ListProperty.

Slider:
   value: root.color[0] = self.value
Slider:
   value: root.color[1] = self.value
Slider:
    value: root.color[2] = self.value

When I attempt to run the app, Python insists that my assignment for the values is invalid syntax. I've looked over the rest of the code and can't find what the problem is.

Here's the entire KV file:

<WelcomeScreen>:
    AnchorLayout:
        anchor_x: 'center'
        anchor_y: 'bottom'
        Button:
            text: "Welcome!"
            size_hint: 0.1,0.1
            on_press: root.manager.current = app.screens[7] 

<PhoneSelection>:
    BoxLayout:
        Button:
            text: "iPhone 4/4s"
            on_press: 
                root.manager.current = app.screens[1] 
                app.vars.phone_type = "iPhone YAYAYA"
                self.text = str(app.vars.phone_type)

<PhotoEditor>
    AnchorLayout:
        anchor_x: 'center'
        anchor_y: 'bottom'
        Button:
            text: 'Color'
            on_press: root.open_popup()

<ColorPopup>
    size_hint: .5, .5
    auto_dismiss: True
    title: 'Hello world'
    AnchorLayout:
        anchor_x: 'center'
        anchor_y: 'center'
        AnchorLayout:
            anchor_x: 'center'
            anchor_y: 'bottom'
            Button:
                text: 'Click me to dismiss'
                on_press: root.dismiss()
        AnchorLayout:
            anchor_x: 'center'
            anchor_y: 'center'
            BoxLayout:
                orientation: 'vertical'
                Slider:
                    value: root.color[0] = self.value
                Slider:
                    value: root.color[1] = self.value
                Slider:
                    value: root.color[2] = self.value

And here's the Python file:

from kivy.app import App
from kivy.uix.scatter import Scatter
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.colorpicker import ColorPicker
from kivy.logger import Logger
from kivy.graphics import Color, Ellipse, Line
from kivy.properties import ListProperty
#from editor import PhotoEditor
import random

#Each class def is a different screen.
class WelcomeScreen(Screen):
    def do_stuff():
        pass

class PhoneSelection(Screen):
    pass

class StyleSelection(Screen):
    pass

class ColorSelection(Screen):
    pass

class DesignSelection(Screen):
    pass

class UploadPhoto(Screen):
    pass

class PatternSelection(Screen):
    pass

class PhotoEditor(Screen):
    color = ListProperty([1,1,1,1])
    def open_popup(self):
        popup = ColorPopup()
        popup.open()

class Confirm(Screen):
    pass

class Pay(Screen):
    pass

class ThankYou(Screen):
    pass

class ColorPopup(Popup):
    pass

class Variables():
    phone_type = ""
    phone_color = ""
    phone_style = ""
    phone_design_option = ""
    total_price = 0.0

#This is the main class that has all the app info.
class MainApp(App):
    #list of names for each screen. Each name is used as an ID when changing the current screen.
    screens = ["welcome","choose_phone","choose_style","choose_color","choose_design","upload_photo","choose_pattern","photo_edit","confirm","pay","thanks"]
    vars = Variables()
    def build(self):
        #The manager that holds all the screens and allows transitioning between them.
        SM = ScreenManager()

        #list of names for each screen. Each name is used as an ID when changing the current screen.
        screens = ["welcome","choose_phone","choose_style","choose_color","choose_design","upload_photo","choose_pattern","photo_edit","confirm","pay","thanks"]

        #Add all screens to the manager and assign the corresponding ID.
        SM.add_widget(WelcomeScreen(name=screens[0]))
        SM.add_widget(PhoneSelection(name=screens[1]))
        SM.add_widget(StyleSelection(name=screens[2]))
        SM.add_widget(ColorSelection(name=screens[3]))
        SM.add_widget(DesignSelection(name=screens[4]))
        SM.add_widget(UploadPhoto(name=screens[5]))
        SM.add_widget(PatternSelection(name=screens[6]))
        SM.add_widget(PhotoEditor(name=screens[7]))
        SM.add_widget(Confirm(name=screens[8]))
        SM.add_widget(Pay(name=screens[9]))
        SM.add_widget(ThankYou(name=screens[10]))

        #Set the current screen to the welcome screen.
        SM.current = screens[0]
        return SM

#Runs the app.
if __name__ == "__main__":
    t = MainApp();
    t.run()
1

There are 1 answers

0
inclement On BEST ANSWER
value: root.color[0] = self.value

This is the syntax to set the value of your value property, but your python code is assignment which doesn't return a value, so the syntax is invalid.

Did you mean instead:

on_value: root.color[0] = self.value

This will update root.color when the value is changed by the user.