Python Block Drawing LIbrary

Lately I’ve been playing around with the idea of creating Pong in pythons tkinter library.  I’ve got drawing blocks in tkinter down, so much so that I’ve made a derpy library for it which will undoubtedly change a lot as i get more practice.  If you happen to be classy enough to have Python installed, feel free to load up this bit of code and play around with it.  Also, looking back, refresh was a really strange word choice, o well.  I still need to add some game logic, a main loop (probably while True: with a time.sleep() delay), and a front end.  Who knows if I’ll finish this project, but I’m having fun.

from tkinter import *
import time
import os

#initialize vars
objList = []

def clear():

class Block:
    def __init__(self,x,y,w,h,hue):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.hue = hue

def createCanvas(h,w):
    root = Tk()
    return Canvas(root, width=w, height=h)

def drawBox(x,y,w,h,hue):

def refresh(bkgHue):
    for obj in objList:
        drawBox(obj.x, obj.y, obj.w, obj.h, obj.hue)

#some code to get you started
canvas = createCanvas(200,200)
block1 = Block(10,10,10,10,”green”)
block2 = Block(30,30,10,10,”yellow”)



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s