Site Sponsors:
PyGame Example - The Lazy Star 
Had a chance to teach a bunch of wonderful new Python students this month.

Several were interested in using pygame, so we put together the following demonstration.

Thought we would share it.

Note that - before running pygame - that we will need to use pip (or pip3) to install the pygame package (e.g: pip3 install pygame)

Linux folks should install packages using PIP as to get those Super Cow Powers (i.e either su, or sudo should moo nicely.)

import pygame

screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Hackin' Around!")

back_color = (128, 45, 100) # Ubuntu Default

clock = pygame.time.Clock()

def stat(zEvent):
if zEvent is None:
loc = zEvent.__dict__['pos']
basicfont = pygame.font.SysFont(None, 72)
text = basicfont.render('*', True, (255, 0, 0), back_color)
screen.blit(text, loc)
except Exception as ex:
print("Exceptional:", zEvent)

while True:
for event in pygame.event.get():
if event.type == pygame.QUIT: # closing the window
clock.tick(12) # fps

Note that 'fps' in the above stands for "frames per second." The lower, the slower. -You can set it to 1000 or so to speed things up ... allot!

Sharing is caring!


p.s. If you want to learn more about programing in Python 3, then here is a discount coupon to my on-line training.

[ view entry ] ( 443 views )   |  permalink  |  related link
Microsoft Triumph! 
Some people say that we POSIX guys are biased. --Many believe that wee open source folks have something against commercial software platforms / tools.

In my case - as well as everyone else I know - nothing could be farther from the truth!

In very fact, while I personally do allot on free & open Linux / LAMP / POSIX worlds, when it comes to raking in the big bucks I - more often than not - find myself working with Microsoft technologies.

Indeed, we'll rake in ever more $$,$$$ when we combine POSIX, Microsoft, and other tools together (The higher the 'tech is stacked, the fewer there be to tackle it, my friends ...!)

Modern C/C++

While many marvelous tools have come and gone, at the time of this writing - and in my opinion - there are virtually NO decent open graphical tool sets for C/C++. --And I have tried just about all of them! (Conclusion: Never trust a developer - favoring ONE language - to concoct a language-savvy tooling ... for another?)

So as I turned my weary eyes back to Visual Studio this day, I was overjoyed to discover that "The Empire" has finally started to support those of us who - uh - like to live ... on "Hoth" ! (Cygwin and MinGW under Visual Studio? CLICK HERE!)

(Hey 'Darth: Say "CHEEESE?")

Indeed, after downloading Visual Studio's 2017 Community Edition so that I could play with libtcod (they no longer liked my '2013 Pro) I tell 'ya truly - that a relatively new editor - known as Visual Studio Code - works REAL WELL out of the box... even in our icy monster-caves:

Sure - when time for working on C# & VB comes again (as it always will!) I will surely upgrade the '2013 to VS 2017 -- or whatever else the emperor de-jure requires us to buy so as to continue to move our hostage-ware VS Projects (like libtcod!) forward in their empire.

In the mean time however, it is VERRRRY refreshing to be able to quickly do a 'git - edit - as well as work with the console tools directly from Visual Studio Code, Express, or the Community Editions!

Yet THAT - as we might say - and to complete the analogy - is merely the tip of this iceberg of what the entire VS Family-Empire can do for Modern C/C++! =)

(And yes Slytherin, the 'Empire now even supports Python!)

Want to learn more? Then here is how to "Use any C++ Compiler with Visual Studio"!

[ view entry ] ( 460 views )   |  permalink  |  related link
"Just Do It:" Graphical Command-Line Parameters for Python 3 
(UPDATED 2018-11-06: Code now available at GitHub)

There seems to be a huge line between those who want to use console applications, and those who have the need for a GUI.

When using Python however, such lines need not exist: It can be easy to jump between the the Graphical & Textual Worlds!

from tkinter import *

# Mission: Create a way to query a user for command-line values.
# Mission statement implies the encapsulation of a GUI paradigm.
# Here is how to do so using tkinter under Python 3.

''' Prompter: Graphically get a dictionary of command-line strings from a user.
Dictionary result is empty when the `cancel` button has been pressed, else the results
will contain the tag-value pairing (i.e. Dictionary keys match the fields requested, to
get the user's response for each field.)
class Prompter:
def __init__(self):
self._dict = None
self._isOk = None
self.last_row = None

def _okay(self):
self._isOk = True

def _cancel(self):
self._isOk = False

def Begin(*fields, title="Input"):
''' Create the frame, add the title, as well as the input fields.'''
from collections import OrderedDict
self = Prompter() = Tk()

self._dict = OrderedDict()

if title:

self.last_row = 0
# zFields (A Label, plus an Entry, in a grid layout)
for ref in fields:
obj = Label(, text=str(ref))
obj.grid(row=self.last_row, column=0)

obj = Entry(, bd=5)
obj.grid(row=self.last_row, column=1)

self.last_row += 1
return self

def End(prompter):
''' Add the closing buttons, center, and pack the Frame.'''
if prompter.last_row is None:
return False
if isinstance(prompter, Prompter) is False:
return False
# zButtons (A Frame in the grid, plus the properly-centered pair of buttons)
bottom = Frame(
bottom.grid(row=prompter.last_row, columnspan=2)
btn = Button(bottom, text="Okay", command=prompter._okay)
btn.pack(side=LEFT, pady=12)

btn = Button(bottom, text="Cancel", command=prompter._cancel)
btn.pack(side=RIGHT, padx=10)

# zCenter (Close enough to make no odds?)
width =
height =
x = (width - / 2
y = (height - / 2"+%d+%d" % (x, y))
return True

def show(self):
from collections import OrderedDict
results = OrderedDict()
if self._isOk is not True:
return results

for ref in self._dict.keys():
results[ref] = (self._dict[ref]).get()
return results

def Prompt(*fields, title="Input"):
''' Basic mission statement completed. '''
self = Prompter.Begin(*fields, title=title)
if Prompter.End(self) is False:
raise Exception("AddButtons: Unexpected Error.")

if __name__ == "__main__":
# Here is how we would use the Prompter from a Console Program:
results = Prompter.Prompt("this", "isa", "test", title="Just Do It!")
if len(results) is 0:
print("Pressed Cancel - no values!")
print("Pressed Okay - got values!")
for ref in results:
print(ref, results[ref])

Taking time to review the test case, all one need do is to provide Prompter.InputStrings() with the queries. The title is optional.

Upon activation, Prompter.InputStrings() will create a reasonable-looking user interface, screen-center it & use it to query the user, then return a dictionary of the string response(s) provided.

When the user presses "cancel," the dictionary will be empty.

WIPI Results

Of course, one of the most annoying things about Dict()ionaries in this man's world is - at the time of this writing - the eccentric ordering of their key:value pairs.

Submitted for your perusal therefore, allow me to offer up Prompter.InputOrder() for your more predictable re-usages:

def InputOrder(*fields, title="Input"):
results = Prompter.InputStrings(*fields, title=title)
if len(results) is 0:
return [*zip([],[])]
data = []
for ref in fields:
results = zip(fields, data)
return [*results]

Designed to work exactly as Prompter.InputStrings() (sans the dict(), of course):

-Here be the test case:
    results = Prompter.InputOrder("this", "isa", "test", title="Just Do It!")
if len(results) is 0:
print("Pressed Cancel - no values!")
print("Pressed Okay - got values!")
for ref in results:
print(ref[0], ref[1])
-With the much more predictable, everything is WHERE-I-PUT-IT (W.I.P.I = 'wippy') 'list of lists' result paring:

[ view entry ] ( 703 views )   |  permalink  |  related link

<<First | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Next> Last>>