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:
JavaScript
x
27
27
1
def show_movepop():
2
show = MovePop()
3
movepopWindow = Popup(title="Move", content=show, size_hint=(None, None),size=(400,400))
4
movepopWindow.open()
5
6
class MovePop(FloatLayout):
7
pass
8
9
class MainWindow(Screen):
10
def movebtn(self):
11
show_movepop()
12
13
class StatsWindow(Screen):
14
pass
15
16
class WindowManager(ScreenManager):
17
pass
18
19
kv = Builder.load_file("gamegui.kv")
20
21
class MainFloatApp(App):
22
def build(self):
23
return kv
24
25
if __name__ == "__main__":
26
MainFloatApp().run()
27
and this is my .kv file:
JavaScript
1
51
51
1
WindowManager:
2
MainWindow:
3
StatsWindow:
4
5
<Button>
6
font_size:40
7
color:0.3,0.6,0.7,1
8
size_hint: 0.5, 0.1
9
10
<MainWindow>:
11
name: "mainscreen"
12
13
FloatLayout
14
Button:
15
text: "MOVE"
16
id: move
17
pos_hint: {"x":0, "y":0.1}
18
on_release: root.movebtn()
19
20
Button:
21
text: "ACTION"
22
id: action
23
pos_hint: {"x":0.5, "y":0.1}
24
25
Button:
26
text: "EXAMINE"
27
id: examine
28
pos_hint: {"x":0, "y":0}
29
30
Button:
31
text: "STATS"
32
id: stats
33
pos_hint: {"x":0.5, "y":0}
34
on_release:
35
app.root.current = "statsscreen"
36
root.manager.transition.direction = "left"
37
38
<StatsWindow>:
39
name: "statsscreen"
40
Button:
41
text: "Back"
42
on_release:
43
app.root.current = "mainscreen"
44
root.manager.transition.direction = "right"
45
46
<MovePop>:
47
Button:
48
text: "!"
49
pos_hint: {"x":0.1, "y":0.5}
50
on_release:
51
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
JavaScript
1
3
1
class MovePop(FloatLayout):
2
pass
3
to:
JavaScript
1
3
1
class MovePop(AnchorLayout):
2
pass
3
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.