В моем приложении у меня есть GameScreen с виджем ClueButton1 с некоторым текстом. Нажатие этой кнопки приводит пользователя к ClueScreen (с помощью Kivy Screen Manager), который имеет 4 кнопки, каждый из которых является ответом. Как изменить атрибут background_normal ClueButton1 на GameScreen, когда пользователь нажимает правильный ClueAnswerButton1 на ClueScreen?Изменить атрибут виджета кнопки Kivy, нажав кнопку на другом экране
Я уже пытался назначить ClueButton1 идентификатор и использования, что в четкости check_choice(), как GameScreen.cluebutton1id.background_normal = ..., но получаю сообщение об ошибке:
AttributeError: 'kivy.properties.ObjectProperty' object has no attribute 'background_normal'
код main.py здесь :
class GameScreen(Screen):
...
class ClueScreen(Screen):
...
def check_choice(self):
if self.choice0.state == 'down':
if self.choice0.text == self.correct:
self.message.text = "[color=006600]Correct! Click back to game and keep" \
"playing![/color]"
self.choice0.background_disabled_down = 'atlas://img/myatlas/green_button5'
self.choice0.disabled = True
self.choice1.disabled = True
self.choice2.disabled = True
self.choice3.disabled = True
return
else:
self.message.text = "Try again"
self.choice0.background_disabled_down = 'atlas://img/myatlas/red_button5'
self.choice0.disabled = True
...
И .kv код здесь:
<GameScreen>:
GeneralFloatLayout:
GeneralAnchorLayout:
GeneralBoxLayout:
GameGridLayout:
ClueButton1:
text: root.question
on_press: root.manager.current = 'clue_screen';
<ClueScreen>:
message: message
choice0: choice0
choice1: choice1
choice2: choice2
choice3: choice3
ClueBoxLayout:
ClueLabel:
text: "[color=0046C3]" + "Put label Here" + "[/color]"
ClueMessage:
id: message
ClueAnswerButton1:
id: choice0
on_press: root.check_choice()
ClueAnswerButton1:
id: choice1
on_press: root.check_choice()
ClueAnswerButton1:
id: choice2
on_press: root.check_choice()
ClueAnswerButton1:
id: choice3
on_press: root.check_choice()
ClueGridLayout:
ReturnButton:
text: 'Back to game'
on_press: root.manager.current = 'game_home'