“Hello World!: Computer Programming for Kids and Other Beginners” Python book co-author and elementary school student Carter Sande introduces PythonCard for making a graphical user interface in Python. He shows a Fahrenheit to Celsius temperature converter and a hangman game. His dad and co-author Warren Sande appears with him.
Actors, Exceptions and Either[failure, success]
3 months ago

Way to go Carter and Dad!!! You guys are great. I wish you'd been around when I was a kid. I just turned 20 but I have your book and I follow your blog because it makes it EASY--did you see that, EASY--for me to follow along with Programming!
ReplyDeleteI'm not good yet and right now my PC keeps crashing but hopefully I'll write my first program soon.
Python 3 .xwill not run PythonCard because it hates this code which I think is said the correct way:
ReplyDeletedef _parseHandlers(self):
"""
Find all of the methods in this object that are
PythonCard handlers, and register them.
"""
# KEA 2004-03-05
# an even slicker way of finding event handlers
# using the inspect module
pythoncardMethods = []
# KEA 2004-05-09
# if we use bound methods then we'll have to change the
# initialization order so that Scriptable.__init__
# is done after the object is actually created
# all _dispatch methods have to be updated to use bound
# methods if this is changed
methods = inspect.getmembers(self.__class__, inspect.ismethod)
## # use bound methods instead of the class unbound methods
## methods = inspect.getmembers(self, inspect.ismethod)
for m in methods:
if m[0].split('_')[0] == 'on':
pythoncardMethods.append(m[1])
map(self._addHandler, pythoncardMethods)
I wonder why Python 3.x hates this, because I think it is correct.
Warren Sande replies:
ReplyDelete”As far as we know, PythonCard is not compatible with Python 3.x. Since PythonCard is no longer under development, it is not likely that PythonCard will ever be compatible with Python 3.x. I suggest folks who want to use PythonCard (including readers of our book) use Python 2.5.”
After I finally decided to stick with Python 2.5, every example in the "Hello World" book was working.
ReplyDeleteI also saw something weird with the GUI. It is that when I make an ImageButton's size larger than the dimensions of the image file it uses, screenshots of the windows behind border around the image.
|--------------------------------------------------------------------------------------------------------------|
ReplyDelete| Even though the main development of PythonCard is dead, here is another useful component... |
| FloatSpinner component - component I created mainly for use in the temperature converter program. |
| Just copy the code below and save it as C:\Python27\Lib\site-packages\PythonCard\components\floatspinner.py, |
| exit and reopen Resource Editor, and have fun with your new FloatSpinner component! |
|--------------------------------------------------------------------------------------------------------------|
import wx
from wx.lib.agw import floatspin
from PythonCard import event, widget
from PythonCard.components import spinner
FloatSpin = floatspin.FloatSpin
class FloatSpinnerSpec(widget.WidgetSpec):
def __init__(self):
events = list(spinner.SpinnerEvents)
attributes = {
'digits': {'presence': 'optional', 'default': 13},
'format': {'presence': 'optional', 'default': '%f'},
'increment': {'presence': 'optional', 'default': 0.001},
'min': {'presence': 'optional', 'default': 0.000},
'max': {'presence': 'optional', 'default': 100.000},
'value': {'presence': 'optional', 'default': 0.000}
}
widget.WidgetSpec.__init__(self, 'FloatSpinner', 'Spinner', events, attributes)
class FloatSpinner(widget.Widget, FloatSpin):
_spec = FloatSpinnerSpec()
def __init__(self, aParent, aResource):
FloatSpin.__init__(self, aParent, widget.makeNewId(aResource.id),
aResource.position, aResource.size, 0,
aResource.value, aResource.min, aResource.max,
aResource.increment, aResource.digits,
floatspin.FS_LEFT, aResource.name)
widget.Widget.__init__(self, aParent, aResource)
self._bindEvents(event.WIDGET_EVENTS + spinner.SpinnerEvents)
def setValue(self, value):
if value > self.max: value = self.max
if value < self.min: value = self.min
FloatSpin.SetValue(self, value)
digits = property(FloatSpin.GetDigits, FloatSpin.SetDigits)
format = property(FloatSpin.GetFormat, FloatSpin.SetFormat)
increment = property(FloatSpin.GetIncrement, FloatSpin.SetIncrement)
min = property(FloatSpin.GetMin, lambda self, newMax: self.SetRange(self.min, newMax))
max = property(FloatSpin.GetMax, lambda self, newMin: self.SetRange(newMin, self.max))
value = property(FloatSpin.GetValue, setValue)
from PythonCard import registry
import sys
registry.Registry.getInstance().register(sys.modules[__name__].FloatSpinner)
I'm using your book and I have encountered a problem.
ReplyDeletePythonCard
----------
How do I create a new component WHILE the program is running?
I'm making Python Computer Stats(Like task manager except You can only view stuff)
On a computer with all required modules , python ,Windows 7 and Windows 8(I used Dual boot)