title: Output text in Kivy
body: <p>I am something of a newbie to Python and Kivy but I've made enough progress with Python to write a character generator program for roleplaying games. On the command line, the script works fine. With Kivy, I can get as far as producing a selection list of radio buttons and then clicking a Next button to generate the character. The output of this then goes to the terminal window from which I ran the python script. I've looked all over this site and many others to find out how to display the character stats in the Kivy window. </p>
  
  <pre><code>    #
      # 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)
  </code></pre>
  
  <p>More character races go here and the end of the script looks like this:</p>
  
  <pre><code>    class CharacterGeneratorApp(App):
  
          def build(self):
              self.title="BRP Character Generator"
              return CharacterGenerator()
  
      if __name__ == '__main__':
          CharacterGeneratorApp().run()
  </code></pre>
  
  <p>The charactergenerator.kv looks like this:</p>
  
  <pre><code>    &lt;CharacterGenerator&gt;:
          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()
  </code></pre>
  
  <p>The brp_stats.py module contains all the print functions. One example is the print_stats function:</p>
  
  <p>def print_stats(mystats):
      print ("Characteristics")
      statlist = [ 'STR' , 'CON' , 'SIZ' , 'INT' , 'POW' , 'DEX' , 'APP' , 'EDU' ]
      print ("    ", end="")
      for stat in statlist:
          print (stat," [", mystats[stat], "]", sep="", end= " ")
      print ()</p>
  
  <p>This works fine on the command line and prints its results to the terminal from which the python script was run. The (mystats) parameter is a python dictionary with this format:</p>
  
  <p>{'CON': 13, 'POW': 7, 'STR': 10, 'SIZ': 16, 'INT': 12, 'EDU': 7, 'DEX': 14, 'APP': 14}</p>
  
  <p>How do I get the mystats dictionary displayed in a Kivy Widget?</p>
  
  <p>Regards,
  Colin Brett</p>