I am just trying to set up my menus. I one that looked alright, then I discovered ScreenManager and decided it would be a good thing to use. So I ported my code over to a new file to try it out but the placement of my screen is all out of whack.
What I want:
import kivy
kivy.require('1.9.1')
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.tabbedpanel import TabbedPanelHeader
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.popup import Popup
class MainMenu(Widget):
pass
class G_A_M_E_App(App):
def build(self):
return MainMenu()
if __name__=='__main__':
G_A_M_E_App().run()
and its .kv file
#:kivy 1.9.1
<MainMenu>:
FloatLayout:
width: root.width * 1/3
height: root.height * 1/2
center_x: root.width * 1/2
center_y: root.height * 1/2
canvas:
Color:
rgba: 0,0,1,.5
Rectangle:
size: self.size
pos: self.pos
Button:
size_hint: (.5, .10)
pos_hint: {'center_x': .5, 'center_y' : .90}
text: 'Play'
color: [1, 0, 0, 1]
font_size: self.height * 5/6
border: [25, 25, 25, 25]
Button:
size_hint: (.5, .10)
pos_hint: {'center_x': .5, 'center_y' : .70}
text: 'Load'
color: [1, 0, 0, 1]
font_size: self.height * 5/6
border: [25, 25, 25, 25]
Button:
size_hint: (.5, .10)
pos_hint: {'center_x': .5, 'center_y' : .50}
text: 'New Game'
color: [1, 0, 0, 1]
font_size: self.height * 5/6
border: [25, 25, 25, 25]
Button:
id: help
size_hint: (.5, .10)
pos_hint: {'center_x': .5, 'center_y' : .30}
text: 'Help'
color: [1, 0, 0, 1]
font_size: self.height * 5/6
border: [25, 25, 25, 25]
on_press: root.helpm()
Button:
size_hint: (.5, .10)
pos_hint: {'center_x': .5, 'center_y' : .10}
text: 'Quit'
color: [1, 0, 0, 1]
font_size: self.height * 5/6
border: [25, 25, 25, 25]
1 and heres the one that doesnt look like that
import kivy
kivy.require('1.9.1')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.popup import Popup
class StartMenu(Screen):
pass
class NewGame(Screen):
pass
class LoadGame(Screen):
pass
class ScreenManager(ScreenManager):
pass
sm = Builder.load_file("main.kv")
class G_A_M_E_App(App):
def build(self):
return sm
if __name__=='main__':
G_A_M_E_App().run()
and its .kv file
ScreenManager:
StartMenu:
NewGame:
LoadGame:
<StartMenu>:
name: 'start_menu'
FloatLayout:
width: root.width * 1/3
height: root.height * 1/2
center_x: root.width * 1/2
center_y: root.height * 1/4
canvas:
Color:
rgba: 0,0,1,.5
Rectangle:
size: root.size
pos: root.pos
Button:
size_hint: (.5, .10)
pos_hint: {'center_x': .5, 'center_y' : .90}
text: 'Play'
color: [1, 0, 0, 1]
font_size: self.height * 5/6
border: [25, 25, 25, 25]
Button:
size_hint: (.5, .10)
pos_hint: {'center_x': .5, 'center_y' : .70}
text: 'Load'
color: [1, 0, 0, 1]
font_size: self.height * 5/6
border: [25, 25, 25, 25]
Button:
size_hint: (.5, .10)
pos_hint: {'center_x': .5, 'center_y' : .50}
text: 'New Game'
color: [1, 0, 0, 1]
font_size: self.height * 5/6
border: [25, 25, 25, 25]
Button:
id: help
size_hint: (.5, .10)
pos_hint: {'center_x': .5, 'center_y' : .30}
text: 'Help'
color: [1, 0, 0, 1]
font_size: self.height * 5/6
border: [25, 25, 25, 25]
<NewGame>:
name: 'new_game'
Button:
on_release: app.root.current = 'new'
text: 'New Game'
font_size: 50
<LoadGame>:
name: 'load_game'
Button:
on_release: app.root.current = 'load'
text: 'Load'
font_size: 50
I haven't changed any values for the size I'm still basing it on root and I'm not sure what is affecting it.