色の ListProperty の R、G、および B の値を変更することになっているいくつかのスライダーを備えた単純なポップアップを記述した KV ファイルがあります。
Slider:
value: root.color[0] = self.value
Slider:
value: root.color[1] = self.value
Slider:
value: root.color[2] = self.value
アプリを実行しようとすると、値の割り当てが無効な構文であると Python が主張します。残りのコードに目を通しましたが、何が問題なのかわかりません。
KV ファイル全体は次のとおりです。
<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
Python ファイルは次のとおりです。
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()