Skip to content
Advertisement

Kivy Popup Shows Same Buttons as Main Screen

I’m very new to Kivy (been using for about four hours…) and I’ve hit a wall with popups.

I have a main screen which has four buttons in a float layout. On press down I want the ‘MOVE’ button to open a popup. Now I’ve got this working but the popup contains the same four buttons as my mainscreen.

This is my Python code:

def show_movepop():
    show = MovePop()
    movepopWindow = Popup(title="Move", content=show, size_hint=(None, None),size=(400,400))
    movepopWindow.open()
    
class MovePop(FloatLayout):
    pass

class MainWindow(Screen):
    def movebtn(self):
        show_movepop()

class StatsWindow(Screen):
    pass

class WindowManager(ScreenManager):
    pass

kv = Builder.load_file("gamegui.kv")
           
class MainFloatApp(App):
    def build(self):
        return kv
        
if __name__ == "__main__":
    MainFloatApp().run()

and this is my .kv file:

WindowManager:
    MainWindow:
    StatsWindow:

<Button>
    font_size:40
    color:0.3,0.6,0.7,1
    size_hint: 0.5, 0.1

<MainWindow>:
    name: "mainscreen"

    FloatLayout
        Button:
            text: "MOVE"
            id: move
            pos_hint: {"x":0, "y":0.1}
            on_release: root.movebtn()
            
        Button:
            text: "ACTION"
            id: action
            pos_hint: {"x":0.5, "y":0.1}
        
        Button:
            text: "EXAMINE"
            id: examine
            pos_hint: {"x":0, "y":0}
        
        Button:
            text: "STATS"
            id: stats
            pos_hint: {"x":0.5, "y":0}
            on_release: 
                app.root.current = "statsscreen"
                root.manager.transition.direction = "left"

<StatsWindow>:
    name: "statsscreen"
    Button:
        text: "Back"
        on_release:
            app.root.current = "mainscreen"
            root.manager.transition.direction = "right"

<MovePop>:
    Button: 
        text: "!"
        pos_hint: {"x":0.1, "y":0.5}
        on_release:

Apologies in advance if the above is super dirty, I’m not very efficient :’)

All suggestions appreciated!

Advertisement

Answer

Okay so I don’t know why but it was the FloatLayout that was causing the problem.

Changed

class MovePop(FloatLayout):
    pass

to:

class MovePop(AnchorLayout):
    pass

BoxLayout also got rid of the duplicate buttons but I couldn’t arrange the content on the popup the way I wanted in that layout.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement