2017-09-13 132 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()