KTextSurfaceWriter

A PyGame addon for display text over surface with many dimension bounds
Download

KTextSurfaceWriter Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL
  • Price:
  • FREE
  • Publisher Name:
  • Keul
  • Publisher web site:
  • http://keul.it/

KTextSurfaceWriter Tags


KTextSurfaceWriter Description

A PyGame addon for display text over surface with many dimension bounds KTextSurfaceWriter's goal is to help developers to simply display text inside a pygame.Rect instance. After obtainer a KTextSurfaceWriter instance, you can use its ''draw'' method to display the text over a pygame.Surface.ExamplesHere a fully example of use of this library. Even if I use the Python doctest format, this isn't a politically correct test because I wait for user input and no real tests are done on the results.Maybe someday I'll fix this!However the code in this page is a working example. If you know nothing about doctests, only know that you can run this code simple accessing at the egg source and type: python tests.pyInit all the pygame stuffLets begin loading the KTextSurfaceWrite class >>> from ktextsurfacewriter import KTextSurfaceWriterNow init the minimum pygame environment we need. >>> import pygame >>> from pygame.locals import * >>> import pygame.font >>> pygame.font.init() >>> screen = pygame.display.set_mode((640,480), 0, 32)To make things more complicated, I'll not draw directly on the screen but I get a Surface where I can draw. >>> surface = pygame.Surface( (400,400), flags=SRCALPHA, depth=32 ) >>> surface.fill( (255,255,255,255) ) Now we can blit the surface on the screen. We will repeat this procedure several times so its better create out first dummy function (those functions aren't useful outside this test environment): >>> def blitSurface(): ... screen.blit(surface, (50,50) ) ... pygame.display.update()So we can call it for the first time. >>> blitSurface()This is a graphical test, so we need to delay the drawing and make possible that user can look at results and then go over. We wait for user input before going on. To do this we create a second silly function that we'll call often later. >>> def waitForUserAction(): ... while True: ... ... for event in pygame.event.get(): ... if event.type == QUIT: ... import sys ... sys.exit(0) ... if event.type==KEYDOWN: ... returnOk, lets call it for the first time. >>> waitForUserAction() Requirements: · Python · pygame


KTextSurfaceWriter Related Software