2017-09-13 130 views
0

我所有的程序都可以正常工作,并且我被它阻挡了。没有名称的屏幕

  1. 我的程序会在主应用程序中加载一些启动器屏幕。
  2. 基于用户输入,程序加载完全不同的子应用程序。试图改变屏幕在加载的子应用

这里的时候是哪里出了问题存在的代码发生

  • 问题:

    的.py文件:

    import kivy 
    kivy.require('1.10.0') 
    
    from kivy.app import App 
    from kivy.lang import Builder 
    from kivy.uix.screenmanager import Screen, ScreenManager, FadeTransition 
    from kivy.uix.button import Button 
    from kivy.uix.label import Label 
    
    chClass = "" 
    
    class ScreenManage(ScreenManager): 
        pass 
    
    class Home(ScreenManager): 
        pass 
    
    class TitleScreen(Screen): 
        pass 
    
    class GameScreen(Screen): 
        pass 
    
    class ClassScreen(Screen): 
        pass 
    
    class Warrior1(Screen): 
    
        def GetChClass(self, ch): 
         return ch 
    
        def build(self): 
         ExecuteW().run() 
    
    class Acrobat1(Screen): 
    
        def GetChClass(self, ch): 
         return ch 
    
    class Spell1(Screen): 
    
        def GetChClass(self, ch): 
         return ch 
    
    class HomeScreen(Screen): 
        pass 
    
    class WarriorStats(Screen): 
        pass 
    
    class AcrobatStats(Screen): 
        pass 
    
    class SpellCasterStats(Screen): 
        pass 
    
    class ExecuteW(App): 
        def build(self): 
         return Home() 
    
    class RevengeApp(App): 
        def build(self): 
         return ScreenManage() 
    
    if __name__ == '__main__': 
        print chClass 
        RevengeApp().run() 
    

    revenge.kv:

    #: import sm kivy.uix.screenmanager 
    #: import Factory kivy.factory.Factory 
    #: import builder kivy.lang.Builder 
    
    <ScreenManage> 
        transition: sm.FadeTransition() 
        TitleScreen: 
        ClassScreen: 
        GameScreen: 
        Warrior1: 
        Acrobat1: 
        Spell1: 
        WarriorStats: 
    
    <TitleScreen> 
        on_touch_down: app.root.current = 'Game' 
        canvas: 
         Rectangle: 
          size: self.size 
          pos: self.pos 
          source: 'KnightArmor.jpg' 
        BoxLayout: 
         orientation: 'vertical' 
         Label: 
          font_size: '30sp' 
          color: 1,0,0,1 
          text: "Warrior's Revenge" 
         Label: 
          color: 1,0,0,1 
          text: "Click to Continue:" 
    
    <GameScreen> 
        name: 'Game' 
        canvas: 
         Rectangle: 
          size: self.size 
          pos: self.pos 
          source: 'KnightArmor.jpg' 
        BoxLayout: 
         Button: 
          size_hint: .5,.1 
          text: "New Game" 
          on_release: app.root.current = 'Class' 
         Button: 
          size_hint: .5,.1 
          text: "Load Game" 
    
    <ClassScreen> 
        name: 'Class' 
        BoxLayout: 
         orientation: 'vertical' 
         Label: 
          text: "Choose Your Path" 
         Button: 
          text: "Warrior" 
          on_release: app.root.current = "Warrior1" 
         Button: 
          text: "Acrobat" 
          on_release: app.root.current = "Acrobat1" 
         Button: 
          text: "Spell Caster" 
          on_release: app.root.current = "Spell1" 
    
    <Warrior1> 
        name: "Warrior1" 
        canvas: 
         Rectangle: 
          size: self.size 
          pos: self.pos 
          source: "Warrior.jpg" 
        BoxLayout: 
         orientation: 'vertical' 
         Label: 
          font_size: "20sp" 
          text: "Warrior's are physically strong" 
          color: 0,.5,1,1 
         Label: 
          font_size: "20sp" 
          text: "experts in hand to hand combat," 
          color: 0,.5,1,1 
         Label: 
          font_size: "20sp" 
          text: "and knowledgeable in the ways of" 
          color: 0,.5,1,1 
         Label: 
          font_size: "20sp" 
          text: "arms and armor" 
          color: 0,.5,1,1 
         BoxLayout: 
          orientation: 'horizontal' 
          Button: 
           text: "Cancel" 
           on_release: app.root.current = "Class" 
          Button: 
           name: "warrior_confirm" 
           text: "Confirm" 
           on_release: chClass = root.GetChClass('Warrior') 
           on_release: root.build() 
    

    executew.kv:

    #: import sm kivy.uix.screenmanager 
    
    <Home>: 
        transition: sm.FadeTransition() 
        HomeScreen: 
        WarriorStats: 
    
    <HomeScreen> 
        name: 'Home' 
        AnchorLayout: 
         Button: 
          text: "Stats" 
          on_release: app.root.current = 'WStats' 
    
    <WarriorStats> 
        name: 'WStats' 
        canvas: 
         Rectangle: 
          size: self.size 
          pos: self.pos 
          source: "Warrior.jpg" 
    

    问题: 当点击一个名为“WStats” executew的WarriorStats屏幕在主屏幕上的统计数据按钮应该被加载,但我得到的错误

  • +0

    我想通了......我在我的py文件开关(self)中添加一个函数到我的homescreen类:self.manager.current ='WStats'然后在我的executew.kv - on_release:root.switch( )--- presto问题已解决 –

    +0

    我认为您可以在自己的问题中发布答案,以便您的问题被标记为已解决,并且具有相同问题的其他人可以更轻松地使用您的解决方案。 – syntonym

    回答

    0

    “名为‘WStats’无屏”回答这个问题我想通了,我自己

    class HomeScreen(Screen): 
        def switch(self): 
         self.manager.current = "WStats" 
    

    而且在executew:

    <HomeScreen> 
        Button: 
         text: "Stats" 
         on_release: root.switch()