Printable Version of Topic

Click here to view this topic in its original format

Dream.In.Code _ Perl and Python _ [python] How to get rid of these weird boxes when loading text from a

Posted by: xZachtmx 17 Jun, 2009 - 05:18 PM

Ok im making an alarm clock widget with pygame to draw the text to the screen.
Here is the code:

CODE

import pygame
import time
import sys
from pygame.locals import*
from sys import exit
pygame.init()

windowSize = 600,300

frameRate = 1

#intializing the window
gameWindow = pygame.display.set_mode((windowSize))
pygame.display.set_caption('Zach\'s Alarm clock')
screen = pygame.display.get_surface()

#clocks
# cpu time

clock = time.time()

# counts out seconds
ticker = pygame.time.Clock()

timeFont = pygame.font.Font(None, 120)
dateFont = pygame.font.Font(None, 25)
while True:
    # Limit frame speed to 50 FPS
    #
     time_passed = ticker.tick(frameRate)
    
     #loading alarm time
     file = open("alarm.txt","r")
     alarmHour = file.readline()
     alarmMinute =file.readline()
     file.close()
    
     digiTime = time.strftime('%H:%M:%S')
    
     date = time.strftime("%Y-%m-%d")
    
     # Render the text
     timeText = timeFont.render(digiTime, True, (255, 0, 0), (0, 0, 0))
              
     dateText = dateFont.render(date, True, (0, 255, 0), (0, 0, 0))
     dateTextPosition = (15, 15)    
    
     alarmText = dateFont.render( "Alarm: " + alarmHour + ":" + alarmMinute, True, (0,0,255))  
     alarmTextPosition = (250, 15)      

     # Create a rectangle
     textRect = timeText.get_rect()

     # Center the rectangle
     textRect.centerx = screen.get_rect().centerx
     textRect.centery = screen.get_rect().centery

     # Blit the text
     screen.blit(timeText, textRect)
     screen.blit(dateText, dateTextPosition)
     screen.blit(alarmText, alarmTextPosition)
    
                                                          
     pygame.event.pump()

     keyBState = pygame.key.get_pressed()
    
     if keyBState[K_ESCAPE]:
        exit()
        
     pygame.display.flip()


and the only stuff in the text file are:
CODE

2
55

so its sucessfuly loading the numbers but at the end of both numbers are two rectangular boxes which arent in the text file when i look at it... but it apears to be there as you can see for youself:
Attached Image

Can somone PLEASE help me with this?

Posted by: xZachtmx 18 Jun, 2009 - 08:16 AM

Nevermind. I fixxed it by trimming the boxes of the end.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)