Forum Archive

Pyui pause menu for a scene

sodoku

Hello Pythonista I have a pyui called pawz, with just a text field and a button, that I wanted to use as a pause menu and update the label node with the textfield text when I push the button
Is this possible
Heads up I have the Label 1 that I wanted to use triple quotation marked out because it errors when loading just to show you where I’m having trouble implementing this task

from scene import *

class Game (Scene):
def setup(self):
self.background_color = '#004f82'
ground = Node(parent=self)
x = 0
while x <= self.size.w + 64:
tile = SpriteNode('plf:Ground_PlanetHalf_mid', position=(x, 0))
ground.add_child(tile)
x += 64
self.player = SpriteNode('plf:AlienGreen_front')
self.player.anchor_point = (0.5, 0)
self.player.position = (self.size.w/2, 32)
self.add_child(self.player)
'''
#Label 1
self.card = LabelNode((text[0]),color=('#0016ff'))
self.card.position = (85,760)
self.add_child(self.card)
self.card.size = (100,100)
'''
#pause symbol
self.pause_button = SpriteNode('iow:pause_32', position=(32, self.size.h-32), parent=self)

    #control pause symbol button
def touch_ended(self, touch):
    if self.pause_button.frame.contains_point(touch.location):
        v = ui.load_view('pawz.pyui')
        v.present('sheet')

if name == 'main':
run(Game(), PORTRAIT, show_fps=True)

cvp

@sodoku it is difficult to help you because we don't see indentation of your script...

cvp

@sodoku try this

from scene import *

class Game (Scene):
    def setup(self):
        self.background_color = '#004f82'
        ground = Node(parent=self)
        x = 0
        while x <= self.size.w + 64:
            tile = SpriteNode('plf:Ground_PlanetHalf_mid', position=(x, 0))
            ground.add_child(tile)
            x += 64
        self.player = SpriteNode('plf:AlienGreen_front')
        self.player.anchor_point = (0.5, 0)
        self.player.position = (self.size.w/2, 32)
        self.add_child(self.player)

        #Label 1
        self.card = LabelNode('',color=('#0016ff'))
        #self.card = LabelNode((text[0]),color=('#0016ff'))
        self.card.position = (85,760)
        self.add_child(self.card)
        self.card.size = (100,100)

        #pause symbol
        self.pause_button = SpriteNode('iow:pause_32', position=(32, self.size.h-32), parent=self)

    #control pause symbol button
    def touch_ended(self, touch):
        if self.pause_button.frame.contains_point(touch.location):
            self.v = ui.load_view('pawz.pyui')
            self.v['button1'].action = self.pawz_button_action
            self.v.present('sheet')
            self.v['textfield1'].begin_editing()

    def pawz_button_action(self,sender):
        self.card.text = self.v['textfield1'].text
        self.v.close()

if __name__ == '__main__':
    run(Game(), PORTRAIT, show_fps=True)