簡體   English   中英

Kivy 彈出窗口顯示與主屏幕相同的按鈕

[英]Kivy Popup Shows Same Buttons as Main Screen

我對 Kivy 非常陌生(已經使用了大約四個小時......)而且我已經遇到了彈出窗口。

我有一個主屏幕,在浮動布局中有四個按鈕。 按下時,我希望“移動”按鈕打開一個彈出窗口。 現在我已經完成了這項工作,但彈出窗口包含與我的主屏幕相同的四個按鈕。

這是我的 Python 代碼:

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()

這是 my.kv 文件:

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:

如果上述內容非常骯臟,請提前道歉,我的效率不是很高:')

所有建議表示贊賞!

好的,所以我不知道為什么,但這是導致問題的FloatLayout

改變了

class MovePop(FloatLayout):
    pass

至:

class MovePop(AnchorLayout):
    pass

BoxLayout也擺脫了重復的按鈕,但我無法按照我在該布局中想要的方式排列彈出窗口上的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM