GTK - Basic Number Pad

How to write a Python Program to GTK - Basic Number Pad ?


Solution:

Marvel Comic Downloader Webkit

How to write a Python Program to Marvel Comic Downloader Webkit ?


Solution:

Python - Webkit - Zoom Text

How to write a Python Program to Python - Webkit - Zoom Text ?


Solution:

Post Form Submit with Python

How to write a Python Program to Post Form Submit with Python ?


Solution:

PyGame - Very Basic Jumper

How to write a Python Program on PyGame - Very Basic Jumper ?


Solution:

Blender 3D Game - Add Object

How to write a Python Program to Blender 3D Game - Add Object ?


Solution:

Circle Game in PyGame - POP the Bubbles

How to write a Python Program to Circle Game in PyGame - POP the Bubbles ?


Solution:

#!/usr/bin/env python
#Created by Kris Occhipinti
#http://FilmsByKris.com December 29th 2010
#GPLv3 - http://www.gnu.org/licenses/gpl-3.0.html

import pygame, sys, random          #load pygame module
from pygame.locals import *

w = 800                 #set width of screen
h = 600                 #set height

miss = 0

screen = pygame.display.set_mode((w, h)) #make screen

pygame.display.flip()


class Ball:
   def __init__(self, radius, speed, x, y, color, size):
       if speed == 0:
          speed=2
       self.d = 15
       self.y=y
       self.x=x
       self.size=size
       #speed
       self.yy=speed
       self.xx=speed
       self.radius=radius
       self.color=color
       pygame.draw.circle(screen, self.color, (self.x, self.y), self.radius )


   def cir_mov(self):
       global h, w
       self.d-=1
       self.x+=self.xx
       self.y+=self.yy
       if self.x > w - self.radius:
          self.xx = self.xx*-1
       elif self.x < 0 + self.radius:
          self.xx = self.xx*-1
       elif self.y > h - self.radius:
          self.yy = self.yy*-1
       elif self.y < 0 + self.radius:
          self.yy = self.yy*-1
       pygame.draw.circle(screen, self.color, (self.x, self.y), self.radius )

   def cir_click(self, x, y):
       global miss
       if self.d < 0:
           if x > self.x - self.radius and x < self.x + self.radius:
               if y > self.y - self.radius and y < self.y + self.radius:
                   miss = 1
                   ball.remove(self)
                   if self.size == "L":
                       ball.append(Ball(25, 2, self.x, self.y, (random.randint(1,255),random.randint(1,255),random.randint(1,255)), "S"))
                       ball.append(Ball(25, -2, self.x, self.y, (random.randint(1,255),random.randint(1,255),random.randint(1,255)), "S"))
                 
clock = pygame.time.Clock()
ball = []
ball.append(Ball(50, random.randint(-3,3), 250, 250, (random.randint(1,255),random.randint(1,255),random.randint(1,255)),"L"))
ball.append(Ball(50, random.randint(-3,3), 150, 150, (random.randint(1,255),random.randint(1,255),random.randint(1,255)),"L"))


while 1:
   clock.tick(60)
   for event in pygame.event.get():
       if event.type == pygame.QUIT:
           sys.exit()
       elif event.type == MOUSEBUTTONDOWN:
           print "click"
           x,y = pygame.mouse.get_pos()
           for i in ball:
               i.cir_click(x,y)
       elif event.type == MOUSEBUTTONUP:
           if miss == 0:
               ball.append(Ball(50, random.randint(-3,3), x, y, (random.randint(1,255),random.randint(1,255),random.randint(1,255)),"L"))
           miss = 0

   screen.fill((0,0,0))
   for i in ball:
       i.cir_mov()

   pygame.display.flip()

Simple IRC Bot

How to write a Python Program to Simple IRC Bot ?


Solution:

#!/usr/bin/env python

import sys
import socket
import string
import time

HOST="irc.freenode.net"
PORT=6667
NICK="metalbot"
IDENT="metalbot"
REALNAME="MetalBot"
readbuffer=""

s=socket.socket( )
s.connect((HOST, PORT))
s.send("NICK %s\r\n" % NICK)
s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))

while 1:
    readbuffer=readbuffer+s.recv(1024)
    temp=string.split(readbuffer, "\n")
    readbuffer=temp.pop( )

    for line in temp:
        print line
        line=string.rstrip(line)
        line=string.split(line)

        if "/MOTD" in line:
            print "Connecting..."
            time.sleep(5)
            s.send("JOIN #filmsbykris \r\n")

        if "metalbot" in line:
            print "<===========metabot==============>"
            if "Linux" in line:
                print "<===============Linux==========>"
                s.send("PRIVMSG #filmsbykris : I think Linux is cool!!! \r\n")

        if(line[0]=="PING"):
            s.send("PONG %s\r\n" % line[1])

Linking Buttons to Functions in Python and Qt4-designer

How to write a Python Program to Linking Buttons to Functions in Python and Qt4-designer ?


Solution:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'myui.ui'
#
# Created: Tue Jan  3 11:19:03 2012
#      by: PyQt4 UI code generator 4.8.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

def myfunc():
    print "Hello World"

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(400, 300)
        self.pushButton = QtGui.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(160, 170, 88, 27))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.label = QtGui.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(190, 80, 57, 15))
        self.label.setObjectName(_fromUtf8("label"))

        self.retranslateUi(Form)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), myfunc)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("Form", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Form = QtGui.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())

Blender Mouse Cursor Image

How to write a Python Program to Blender Mouse Cursor Image ?


Solution: