【发布时间】:2021-07-18 09:37:43
【问题描述】:
我用checkboxes 制作了MDDialog。当玩家检查特定的“分数限制”时,我想回调特定的alertdialog(MDDialog)。游戏是用python 3.9.6 kivymd 0.104.2 制作的。这里没有问题。我只是不知道该怎么做。这是我的python 代码:
kv = '''
#:import Factory kivy.factory.Factory
<ItemConfirm>
divider: None
CheckboxLeftWidget:
id: check
score: root.text # makes the score text available from the Checkbox
group: "check"
on_active: app.check_active(self.group) # update app.active
<ConfirmButton@MDFlatButton>:
text: 'CONFIRM'
disabled: not app.active # disabled when app.active is False
on_release: app.score_limit()
<ConfirmDialog>:
title: "Score Limit"
bg_color: (5, 0, 0)
type: "confirmation"
auto_dismiss: False
items:
[Factory.ItemConfirm(text="30"),
Factory.ItemConfirm(text="40"),
Factory.ItemConfirm(text="50")]
buttons: [ Factory.ConfirmButton() ]
'''
class ItemConfirm(OneLineAvatarIconListItem):
pass
class ConfirmDialog(MDDialog):
pass
class Begindup(MDFloatLayout):
aa = 0
def close_winner(self, *args):
self.victory.dismiss()
def __int__(self, numb):
self.aa = numb
def screen2(self, screenId):
if self.pressed:
self.ids.screenId.md_bg_color = 0, 0, 0, 1
self.pressed = not self.pressed
else:
self.ids.screenId.md_bg_color = 1, 1, 1, 1
self.pressed = not self.pressed
def update_turn2(self, teamtwo_turn):
self.ids.teamtwo_turn.text = (f"{teamtwo_turn}'s Turn")
def update_score(self, score_one, *args):
self.ids.score_one.text = score_one
winner = int(self.ids.score_one.text)
if (winner >= 30 and winner <= 39 and self.aa == 0):
self.aa = 1
show_winner(self)
if (winner >= 40 and winner <= 49 and self.aa == 0):
self.aa = 1
show_winnerdup(self)
if (winner >= 50 and winner <= 59 and self.aa == 0):
self.aa = 1
show_winnerdupdup(self)
if (winner >= 60 and winner <= 80 and self.aa == 0):
self.aa = 1
show_winnerf(self)
class MyApp(MDApp):
active = BooleanProperty(False) # keeps track if any Checkbox is active
def show_confirmation_dialog(self, *args):
self.dialog = ConfirmDialog()
self.dialog.open()
def score_limit(self, *args, **kwargs):
self.dialog.dismiss()
self.dialog = None # required to eliminate current group of Checkboxes
self.active = False
def check_active(self, group): # update app.active and return current score limit (or None)
for cb in MDCheckbox.get_widgets(group):
if cb.active:
self.active = True
return cb.score
self.active = False
return None
def build(self):
Builder.load_string(kv)
【问题讨论】: