Pygame simple mouse test problems

Pygame simple mouse test problems

Postby merlinthecat » Sat Nov 09, 2013 12:16 am

Im new to python and pygame and im trying to run a simple mouse test that show what position the mouse is in on the background and tells me when I have clicked it..
The pygame window opens up. The title that I have stated is at the top of the window, but the actual pygame screen is just white and I cant see any text or anything. The background is meant to be white but I cant see any text on the feedback on the mouse.
Any ideas why? Probably something really stupid :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol:



import pygame
from pygame import *
pygame.init()
#set the window size
window = pygame.display.set_mode((800,600) ,0,24)
pygame.display.set_caption("Game Title")
fillcolour=(255,255,255)
window.fill(fillcolour)
pygame.display.update()
#create strings for screen info
text1= "MOUSE DOWN POSITION"
text2= ""
mouse_x=0
mouse_y=0
#endless loop for main
running=True
while running:
for event in pygame.event.get():
pos = pygame.mouse.get_pos()
if event.type == MOUSEBUTTONDOWN:
text1=str(pos)
elif event.type == MOUSEMOTION:
mouse_x = pos[0]
mouse_y = pos[1]
text2="mouse x position "+str(mouse_x)
pygame.display.update()
#convert text to graphics
myfont = pygame.font.SysFont("Britannic Bold", 40)
label1 = myfont.render(text1, 1, (255,0,0))
label2 = myfont.render(text2, 1, (0,0,255))

window.fill
window.blit(label1, (0, 20))
window.blit(label2, (450, 550))
pygame.display.update()
merlinthecat
 
Posts: 4
Joined: Wed Nov 06, 2013 10:52 pm

Re: Pygame simple mouse test problems

Postby metulburr » Sat Nov 09, 2013 4:30 pm

1) use code tags

2)
You are not filling the window giving a blur of text, and display updating twice causing a flicker
Code: Select all
import pygame
from pygame import *
pygame.init()
#set the window size
window = pygame.display.set_mode((800,600) ,0,24)
pygame.display.set_caption("Game Title")
fillcolour=(255,255,255)
window.fill(fillcolour)
#pygame.display.update()
#create strings for screen info
text1= "MOUSE DOWN POSITION"
text2= ""
mouse_x=0
mouse_y=0
#endless loop for main
running=True
while running:
   window.fill(fillcolour)
   for event in pygame.event.get():
      pos = pygame.mouse.get_pos()
   if event.type == MOUSEBUTTONDOWN:
      text1=str(pos)
   elif event.type == MOUSEMOTION:
      mouse_x = pos[0]
      mouse_y = pos[1]
      text2="mouse x position "+str(mouse_x)
      #pygame.display.update()
   #convert text to graphics
   myfont = pygame.font.SysFont("Britannic Bold", 40)
   label1 = myfont.render(text1, 1, (255,0,0))
   label2 = myfont.render(text2, 1, (0,0,255))

   #window.fill
   window.blit(label1, (0, 20))
   window.blit(label2, (450, 550))
   pygame.display.update()


You only need to update the display once. You had 3 lines when you only needed one.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1420
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest