Oct-03-2017, 09:39 AM
(This post was last modified: Oct-03-2017, 09:39 AM by JamieVanCadsand.)
Hey Game Developers...
How can i render tekst from as example an variable like an calculation, string or as example an
file open ?... I try this to learn working with pygame, i want to learn program my own software,
now i get an sum, calculated in python 3.6.2 and i try to render the calculation in pygame tekst...
This is my script, it don't works:
strings, etc ?... this get i need for my future software, this is an simple test...
Can anyone give my an little many example codes ?...
Thanks, Jamie.
EDIT:
This is an in .txt writted script thad i want to try:
How can i render tekst from as example an variable like an calculation, string or as example an
file open ?... I try this to learn working with pygame, i want to learn program my own software,
now i get an sum, calculated in python 3.6.2 and i try to render the calculation in pygame tekst...
This is my script, it don't works:
import pygame
import sys
pygame.init()
WHITE = (255, 255, 255)
RED = (0, 255, 0)
BLACK = (0, 0, 0)
size = (640, 480)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("JCads Develop")
done = False
clock = pygame.time.Clock()
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
done = True
screen.fill(WHITE)
pygame.draw.line(screen, RED, [0, 0], [100, 100], 5)
num1 = 36
num2 = 84
call = num1 * num2
font = pygame.font.SysFont('Calibri', 25, True, False)
text = font.render(call, True, BLACK)
screen.blit(text, [250, 250])
pygame.display.flip()
clock.tick(60)
pygame.quit()
sys.exit()Can anyone tell me how i can render tekst from variables like this sum or as example file.open,strings, etc ?... this get i need for my future software, this is an simple test...
Can anyone give my an little many example codes ?...
Thanks, Jamie.
EDIT:
This is an in .txt writted script thad i want to try:
import pygame
import sys
pygame.init()
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
zise = (640, 480)
screen = pygame.display.set_mode(zise)
pygame.display.set_caption("JCads Develop")
done = False
clock = pygame.time.Clock()
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
done = True
fle = open("myFile.txt", "r")
fname = fle.name()
fclos = fle.closed()
screen.fill(WHITE)
fle_text_basic = pygame.font.SysFont("calibri", 1, True, False)
fle_text_name = pygame.font.SysFont("calibri", 1, False, False)
fle_text_clos = pygame.font.SysFont("calibri", 1, False, False)
fle_text_basic.render("FILE READING: ", True, BLACK)
fle_text_name.render("Name: ".format(fname), True, BLACK)
fle_text_clos.render("Closed: ".format(fclos), True, BLACK)
screen.blit(fle_text_basic, (320, 240))
screen.blit(fle_text_name, (320, 230))
screen.blit(fle_text_clos, (320, 220))
pygame.display.flip()
clock.tick(60)
pygame.quit()
sys.exit()
