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
#color.py
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  :"))
screen=pygame.display.set_mode((640,480),0,24)
pygame.display.set_caption("colour testing ")
 
while True:
 for i in pygame.event.get():
  if i.type==QUIT:
   exit()
 screen.fill((r, g, b))
 pygame.display.update()

Run the file by python color.py

Window will appear with the resultant color …

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

Advertisement

How to get IP address in Python

Hi..to 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(('google.com', 0))
s.getsockname()[0]

Thats it…:)