4. Final version of the Zombies question show¶
xxxxxxxxxx
from browser import document, html
from browser.widgets.dialog import Dialog
def create_element(audio_url, audio_name):
print(f"Creating the audio element {audio_url}")
document <= html.AUDIO(id=audio_name, src=audio_url)
def start_audio(element):
document[element].play()
def pause_audio(element):
document[element].pause()
correct = incorrect = 0
# Correct sound
create_element("http://www.superluigibros.com/downloads/sounds/SNES/SMRPG/wav/smrpg_correct.wav", "correct")
# Incorrect sound
create_element("https://bigsoundbank.com/UPLOAD/ogg/1684.ogg", "incorrect")
d = Dialog("Zombies Question Show", top=20, left=20)
Activity: 4.1 ActiveCode (ac_l50_4a_en)
Something important is missing.
The results of each option!

Let’s change the window to add a label that changes its value.
The value will increase every time the respective button is pressed.
xxxxxxxxxx
from browser import document, html, bind
from browser.widgets.dialog import Dialog
def create_element(audio_url, audio_name):
print(f"Creating the audio element {audio_url}")
document <= html.AUDIO(id=audio_name, src=audio_url)
def start_audio(element):
document[element].play()
def pause_audio(element):
document[element].pause()
correct = incorrect = 0
# Correct sound
create_element("http://www.superluigibros.com/downloads/sounds/SNES/SMRPG/wav/smrpg_correct.wav", "correct")
# Incorrect sound
create_element("https://bigsoundbank.com/UPLOAD/ogg/1684.ogg", "incorrect")
Activity: 4.2 ActiveCode (ac_l50_4b_en)
Great! Everything works perfectly.
You can change the audio for each option.
The boss is happy with the Zombies Question Show.

4.1. Remember¶
Use of the functionalities with the
brython
component.- It is not the only way to create graphical interfaces.
Use of third-party library:
pygame
andtkinter
.
- To handle events, an event controller is used.
Event controller: function that is executed when the event occurs.
Activity: 4.1.1 Poll (TWP50E)
You have attempted 1 of 4 activities on this page