0
votes

Edit:

Long story short, I am looking for a way to switch a Label widget to Buttons. I have a Label with text in it, and I want to make it into 4 Buttons (2x2), and be able to switch between the two.

I am beginning a choose your own adventure game and and having some trouble conceptualizing the best way to code the game that would be efficient and less taxing for the device/computer. The idea is that you go through some dialogue, and the container holding the widget for the dialogue would then have buttons for choices. I would like to find the best way to switch between going through dialogue and making choices. I've come up with a few ideas, some of which include writing code so that upon button press widgets are added and removed, and another idea (which is easier to implement but probably inefficient), is to create an entirely new screen used only for making choices, with everything being the same except for the middle widget which used to hold a text Label, but now will contain a vertical BoxLayout, with two BoxLayouts within for 4 buttons. Here is the code in the .kv file:

#:import FadeTransition kivy.uix.screenmanager.FadeTransition

<RootScreen>:
    transition: FadeTransition() 
    StartScreen:
    LevelOneBedroomScreen:
    LevelOneBedroomScreenchoice:

<StartScreen>:
    name: 'start'
    canvas.before:
        Rectangle:
            pos: self.pos
            size: self.size
            source: 'start_screen.png'
    FloatLayout:
        Image:     
            source: 'start_screen.png'
            allow_stretch: True
            keep_ratio: False
            size_hint: 1, 1
        Button:
            text: 'Start'
            size_hint: 0.4, 0.3
            pos_hint: {'center_x':.5, 'center_y':.5}
            font_size: 70
            on_release: root.manager.current = 'level one bedroom'                  
<LevelOneBedroomScreen>:
    name: 'level one bedroom'
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Image of Bedroom'
        Label:
            text: 'Dialogue Text'
    BoxLayout:
        size_hint_y: .2
        Label:
            text: 'left arrow'
        Button:
            text: 'choose'  
            on_release: root.manager.current = 'level one bedroom choice'           
        Label:
            text: 'right arrow'         
<LevelOneBedroomScreenChoice>:
    name: 'level one bedroom choice'
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Image of Bedroom'
        BoxLayout:
            orientation: 'vertical'
            BoxLayout:
                Button:
                    text: 'choice 1'
                Button:
                    text: 'choice 2'
            BoxLayout:
                Button:
                    text: 'choice 3'
                Button:
                    text: 'choice 4'
    BoxLayout:
        size_hint_y: .2
        Label:
            text: 'left arrow'
        Button:
            text: 'home'    
            on_release: root.manager.current = 'level one bedroom'          
        Label:
            text: 'right arrow' 

It's a rough idea and the structure of the code will likely change but I'm just beginning to conceptualize the logic and I'm wondering if there's a better way to do it (there probably is). I'll be out for a few hours, but will be able to respond to any responses when I get back, thank you in advanced and I apologize if I failed to include relevant information or if this query is not appropriate for this website, I'm still new to Python (and coding in general), and very new to Kivy.

edit: My last idea is to make a dedicated area on the screen for making choices, but if possible I'd like to be able to switch between dialogue and buttons for a sleeker feel.

1
What is your problem ?, I lost a lot with your long story, focus on the point and eliminate the irrelevant.eyllanesc
I apologize, I inserted an edit at the top of the question, and I hope it is straightforward enough.immeeh
As my answer indicates, use Screen, what is the problem with the code you are showing?eyllanesc

1 Answers

0
votes

Why don't you turn to RecycleView? It is the widget the contents of which is controlled dynamically by data (which exactrly is a list of dicts), and can handle any combination of widgets inside of it.