I've got a working boggle app as my first pythonista project, I like it and it's functional, but I want to add some pizzaz to it and that's where I'm having trouble.
You can see the whole (very simple) project at https://github.com/rgregory1/boggle_pythonista
I have a function called button_press that rolls the dice and adds text to the 'dice' labels. I want to change the function to show a random assortment of dice once a second for 3 times, then leave the last one there for the game. I can make it happen, but it won't show the dice until the function finishes, so in effect is that it blanks for 3 seconds then continues.
I managed to run a timer at the same time as my other functions with the @ui.in_background decorator, but that won't work for this one for some reason.
Here is my code (shortened for 4 dice rather than 16 for brevity)
def button_press(self):
print('button was pressed')
self.title = "Play Game"
dice_rolls = roll_all_dice(dice)
label1.text = str(dice_rolls[0])
label2.text = str(dice_rolls[1])
label3.text = str(dice_rolls[2])
label4.text = str(dice_rolls[3])
with open('dice_rolls.json', 'w') as f:
json.dump(dice_rolls, f)
countdown()
main_button.action = show_letters
The effect I want would be this:
def button_press(self):
print('button was pressed')
self.title = "Play Game"
dice_rolls = roll_all_dice(dice)
label1.text = str(dice_rolls[0])
label2.text = str(dice_rolls[1])
label3.text = str(dice_rolls[2])
label4.text = str(dice_rolls[3])
time.sleep(1)
dice_rolls = roll_all_dice(dice)
label1.text = str(dice_rolls[0])
label2.text = str(dice_rolls[1])
label3.text = str(dice_rolls[2])
label4.text = str(dice_rolls[3])
time.sleep(1)
dice_rolls = roll_all_dice(dice)
label1.text = str(dice_rolls[0])
label2.text = str(dice_rolls[1])
label3.text = str(dice_rolls[2])
label4.text = str(dice_rolls[3])
with open('dice_rolls.json', 'w') as f:
json.dump(dice_rolls, f)
countdown()
main_button.action = show_letters
I tried moving this chunk to a function to make it look better,
dice_rolls = roll_all_dice(dice)
label1.text = str(dice_rolls[0])
label2.text = str(dice_rolls[1])
label3.text = str(dice_rolls[2])
label4.text = str(dice_rolls[3])
but I thought I'd leave it in a block to try and problem solve it?
Thanks for any help!