[英]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.我对 Kivy 非常陌生(已经使用了大约四个小时......)而且我已经遇到了弹出窗口。
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:这是我的 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()
and this is my.kv file:这是 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:
Apologies in advance if the above is super dirty, I'm not very efficient:')如果上述内容非常肮脏,请提前道歉,我的效率不是很高:')
All suggestions appreciated!所有建议表示赞赏!
Okay so I don't know why but it was the FloatLayout
that was causing the problem.好的,所以我不知道为什么,但这是导致问题的FloatLayout
。
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. BoxLayout
也摆脱了重复的按钮,但我无法按照我在该布局中想要的方式排列弹出窗口上的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.