Kivy 弹出窗口显示与主屏幕相同的按钮
Kivy Popup Shows Same Buttons as Main Screen
我是 Kivy 的新手(已经使用了大约四个小时......)并且我遇到了弹出窗口问题。
我有一个主屏幕,它有四个浮动布局的按钮。按下时,我希望 'MOVE' 按钮打开一个弹出窗口。现在我已经开始工作了,但是弹出窗口包含与我的主屏幕相同的四个按钮。
这是我的 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()
这是我的 .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
也摆脱了重复的按钮,但我无法按照我想要的布局方式排列弹出窗口中的内容。
我是 Kivy 的新手(已经使用了大约四个小时......)并且我遇到了弹出窗口问题。
我有一个主屏幕,它有四个浮动布局的按钮。按下时,我希望 'MOVE' 按钮打开一个弹出窗口。现在我已经开始工作了,但是弹出窗口包含与我的主屏幕相同的四个按钮。
这是我的 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()
这是我的 .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
也摆脱了重复的按钮,但我无法按照我想要的布局方式排列弹出窗口中的内容。