Kivy

时间:2016-07-13 14:04:35

标签: python kivy

我是Python和Kivy的新手,但我已经在Python上取得了足够的进展,为角色扮演游戏编写角色生成器程序。在命令行上,脚本工作正常。使用Kivy,我可以生成单选按钮的选择列表,然后单击“下一步”按钮生成角色。然后输出到我运行python脚本的终端窗口。我已经浏览了这个网站和其他许多人,以了解如何在Kivy窗口中显示角色统计数据。

    #
    # BRP Character Generator
    #

    import sys
    from kivy.app import App
    from kivy.uix.label import Label
    from kivy.uix.checkbox import CheckBox
    from kivy.uix.gridlayout import GridLayout
    from kivy.uix.boxlayout import BoxLayout
    from kivy.uix.button import Button
    from kivy.properties import StringProperty, ListProperty, DictProperty
    from kivy.uix.widget import Widget

    from brp_stats import *
    from dice_roller import *

    race = ''
    statblock = ''

    class CharacterGenerator(GridLayout):

        statblock = DictProperty({})

        def leave(x):
            print('Exiting BRP Character Generator')
            sys.exit()

       def human(self,a,b):
            if b==True: 
                self.Status="human"
                race=self.Status
                print (race)
                statblock = human()
                characteristic_rolls = rolls(statblock)
                skill_category_modifiers = scm(statblock)
                skill_category_bonuses = scb(statblock)
                printcharacter(self, statblock,characteristic_rolls,skill_category_modifiers,skill_category_bonuses)

更多的角色比赛在这里,脚本的结尾如下:

    class CharacterGeneratorApp(App):

        def build(self):
            self.title="BRP Character Generator"
            return CharacterGenerator()

    if __name__ == '__main__':
        CharacterGeneratorApp().run()

charactergenerator.kv看起来像这样:

    <CharacterGenerator>:
        cols: 2
        canvas:
            Color:
                rgb: .2,.2,.2
            Rectangle:
                pos: self.pos
                size: self.size
        Label:
            text: 'Human'
        CheckBox:
            group: 'race_group'
            on_active: root.human(*args)

        Button:
            text: 'Next'
            on_press: root.printcharacter()

brp_stats.py模块包含所有打印功能。一个例子是print_stats函数:

def print_stats(mystats):     打印(&#34;特点&#34;)     statlist = [&#39; STR&#39; ,&#39; CON&#39; ,&#39; SIZ&#39; ,&#39; INT&#39; ,&#39;战俘&#39; ,&#39; DEX&#39; ,&#39; APP&#39; ,&#39; EDU&#39; ]     打印(&#34;&#34;,end =&#34;&#34;)     对于statlist中的stat:         print(stat,&#34; [&#34;,mystats [stat],&#34;]&#34;,sep =&#34;&#34;,end =&#34;&#34; )     print()

这在命令行上运行正常,并将其结果打印到运行python脚本的终端。 (mystats)参数是一个python字典,格式为:

{&#39; CON&#39;:13,&#39; POW&#39;:7,&#39; STR&#39;:10,&#39; SIZ&#39;:16,&# 39; INT&#39;:12,&#39; EDU&#39;:7,&#39; DEX&#39;:14,&#39; APP&#39;:14}

如何在Kivy Widget中显示mystats字典?

此致 科林布雷特

0 个答案:

没有答案