Now handles integers... long way to go
This commit is contained in:
		
							parent
							
								
									905eaed96c
								
							
						
					
					
						commit
						2740e7ea6c
					
				| 
						 | 
					@ -7,6 +7,10 @@ pygame.init()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
width = 600
 | 
					width = 600
 | 
				
			||||||
height = 900
 | 
					height = 900
 | 
				
			||||||
 | 
					num_display = 0
 | 
				
			||||||
 | 
					old_num_display = 0
 | 
				
			||||||
 | 
					num_float = False
 | 
				
			||||||
 | 
					float_precision = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
screen = pygame.display.set_mode((width, height))
 | 
					screen = pygame.display.set_mode((width, height))
 | 
				
			||||||
pygame.display.set_caption('CheesyCalc')
 | 
					pygame.display.set_caption('CheesyCalc')
 | 
				
			||||||
| 
						 | 
					@ -22,13 +26,29 @@ logo_text_2 = cheesy_font.render("Calculator", True, (240, 240, 20))
 | 
				
			||||||
screen.blit(logo_text_1, (width // 2 - logo_text_1.get_width() // 2 + 80, -15))
 | 
					screen.blit(logo_text_1, (width // 2 - logo_text_1.get_width() // 2 + 80, -15))
 | 
				
			||||||
screen.blit(logo_text_2, (width // 2 - logo_text_2.get_width() // 2 + 80, 30))
 | 
					screen.blit(logo_text_2, (width // 2 - logo_text_2.get_width() // 2 + 80, 30))
 | 
				
			||||||
sevenseg_font = pygame.font.Font(os.path.join("font", "Seven Segment.ttf"), 120)
 | 
					sevenseg_font = pygame.font.Font(os.path.join("font", "Seven Segment.ttf"), 120)
 | 
				
			||||||
text = sevenseg_font.render("9378675309", True, (255, 255, 255))
 | 
					 | 
				
			||||||
screen.blit(text, (width // 2 - text.get_width() // 2, 100))
 | 
					 | 
				
			||||||
pygame.draw.rect(screen, (240, 240, 20), pygame.Rect(10, 95, 580, 130), 2)
 | 
					pygame.draw.rect(screen, (240, 240, 20), pygame.Rect(10, 95, 580, 130), 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while True:
 | 
					while True:
 | 
				
			||||||
    for event in pygame.event.get():
 | 
					    for event in pygame.event.get():
 | 
				
			||||||
        if event.type == pygame.QUIT:
 | 
					        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
 | 
				
			||||||
            pygame.quit()
 | 
					            pygame.quit()
 | 
				
			||||||
            sys.exit()
 | 
					            sys.exit()
 | 
				
			||||||
 | 
					        elif event.type == pygame.KEYDOWN and event.key == pygame.K_c:
 | 
				
			||||||
 | 
					            num_display = 0
 | 
				
			||||||
 | 
					            float_precision = 1
 | 
				
			||||||
 | 
					        elif event.type == pygame.KEYDOWN and event.key == pygame.K_PERIOD:
 | 
				
			||||||
 | 
					            #num_float = True
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					        elif event.type == pygame.KEYDOWN and event.key >= pygame.K_0 and event.key <= pygame.K_9 and len(str(num_display)) < 9:
 | 
				
			||||||
 | 
					            if num_display == 0 and event.key != pygame.K_0:
 | 
				
			||||||
 | 
					                num_display = int(chr(event.key))
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                num_display = (num_display * 10) + int(chr(event.key))
 | 
				
			||||||
 | 
					    if num_display != old_num_display:
 | 
				
			||||||
 | 
					        print(f"Number: {num_display}")
 | 
				
			||||||
 | 
					        old_num_display = num_display
 | 
				
			||||||
 | 
					    pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(12, 97, 576, 126))
 | 
				
			||||||
 | 
					    num_show = (num_float == False) 
 | 
				
			||||||
 | 
					    text = sevenseg_font.render(str(num_display) + ".", True, (255, 255, 255))
 | 
				
			||||||
 | 
					    screen.blit(text, (580 - text.get_width(), 100))
 | 
				
			||||||
    pygame.display.flip()
 | 
					    pygame.display.flip()
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user