Beginning with pygame

Hi…to all …today i learnt how to begin with pygame in python

now lets consider getting intensity range of RED,GREEN ,BLUE  inputs from user  and display the resultant colour in window.


#! usr/bin/python
import pygame
from pygame.locals import *
from sys import exit
r=min(255, input("Enter the red colour intensity  :"))
g=min(255, input("enter the green colour intensity : "))
b=min(255, input("enter the blue colour intensity  :"))
pygame.display.set_caption("colour testing ")
while True:
 for i in pygame.event.get():
  if i.type==QUIT:
 screen.fill((r, g, b))

Run the file by python

Window will appear with the resultant color …

Thats it…enjoy coding with pygame….:) Thanks …..:)

How to install pygame in Python

To install Pygame in python

open terminal and type sudo apt-get install python-pygame

give your password to install and give y or yes to install in your system

To check whether it is installed in your system

$ python

>>> import pygame

if you didn’t get errors means pygame is installed in your system.

Thats it…:)

How to get IP address in Python all …today i learnt how to get IP address in python..

To get the Hostname

import socket
print socket.gethostname()

To get the IP Address

import socket
print socket.gethostbyname(socket.gethostname())

we can also check with dummy socket and see the host name

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('', 0))

Thats it…:)