Instant Hacking: an introduction to the art of programming

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

Instant Hacking: an introduction to the art of programming

#1 Post by disciple »

This is a short introduction to the art of programming, with examples written in the programming language Python. (If you already know how to program, but want a short intro to Python, you may want to check out my article Instant Python.) This article has been translated into Italian, Polish, Japanese, Serbian, Brazilian Portuguese, Dutch, and Czech.
http://hetland.org/writing/instant-hacking.html
Note that Python is not usually included in Puppy.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
antiloquax
Posts: 405
Joined: Fri 27 Jan 2012, 09:17

#2 Post by antiloquax »

This looks good. I like Python.
If you don't have Python 3 on your system (Python 2 comes with the devx), you might want to use this pet for Python 3.1.4.
Python 3.1.4

[Edit] The pygame PET I made, does not work - link removed. Instructions on installing pygame follow in a new post].

This website has some useful pets too - Cairo, TK and TCL - which you also need.
I'll also add a couple of useful tutorials I have used:
A Byte of Python
Introduction to Computer Science Using Python and Pygame
mark
Last edited by antiloquax on Fri 17 Feb 2012, 05:29, edited 1 time in total.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#3 Post by disciple »

This website has some useful pets too - Cairo, TK and TCL - which you also need.
What do you mean? You need them for Pygame?

And out of interest, why should people use Python 3? Just because it is the way of the future? Or are there other benefits?
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
antiloquax
Posts: 405
Joined: Fri 27 Jan 2012, 09:17

#4 Post by antiloquax »

When installing Pythong, I needed TK and TCL for the tkinter module, which the Python IDLE relies on.

I must admit that I am not absolutely sure what Cairo does :oops: ! But I couldn't get Python 3 to install properly without it.

I am learning Python 3 mainly because I had never learned Python before, so it seemed to make sense to go with the newer version. Installing it will not harm your existing Python 2.x installation (which many applications need).

Python is on version 3.2.2 (I think). However, Pygame tends to lag behind a bit - the newest version works best with Python 3.1.4.

As I say, I don't know much about the history of Python. One thing I have seen mentioned is that "print" is function like any other. So it's:
>>> print("Hello World")
Rather than
>>> print "Hello World"
etc.

The other reason was that I bought Michael Dawson's (very good) "Python Programming for the Absolute Beginner" - which is about Python3.
My System:Arch-Arm on RPi!
"[url=http://murga-linux.com/puppy/viewtopic.php?t=76049l]RacyPy[/url]" puplet on Toshiba Tecra 8200. PIII, 256 MB RAM.
[url=http://raspberrypy.tumblr.com/]RaspberryPy[/url]: Lobster and I blog about the RPi.

User avatar
GustavoYz
Posts: 883
Joined: Wed 07 Jul 2010, 05:11
Location: .ar

#5 Post by GustavoYz »


User avatar
antiloquax
Posts: 405
Joined: Fri 27 Jan 2012, 09:17

#6 Post by antiloquax »

Thanks, GustavoYz - I'll have a look at that myself, as this question comes up fairly often.
I know that Arch Linux comes with Python 3 as default, which has caused some problems. Since the versions will co-exist happily it seems to me that we should have Python 2.x for software and Python 3.x for leaning to program.
My System:Arch-Arm on RPi!
"[url=http://murga-linux.com/puppy/viewtopic.php?t=76049l]RacyPy[/url]" puplet on Toshiba Tecra 8200. PIII, 256 MB RAM.
[url=http://raspberrypy.tumblr.com/]RaspberryPy[/url]: Lobster and I blog about the RPi.

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#7 Post by Lobster »

I like Python. However I have never been able to create a Gui with Python.
It is usually the first thing I want to do.
Have you done it? How?
As far as I know Python is available in the devx
- so you could use Glade as the GUI creation tool - again never found that straight forward.

Also available in the devx is the genie language which is python and BASIC like - but compiled . . .
http://puppylinux.org/wikka/ValaGenieintro
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
antiloquax
Posts: 405
Joined: Fri 27 Jan 2012, 09:17

#8 Post by antiloquax »

Hi Lobster, I am very much a newbie at Python. You can create GUIs with the tkinter module I mentioned above.

I don't know how to make the buttons DO anything, but I have played around with this (from Michael Dawson's book),
Attachments
buttonsGUI.png
(3.67 KiB) Downloaded 596 times
buttons.png
(39.15 KiB) Downloaded 598 times
My System:Arch-Arm on RPi!
"[url=http://murga-linux.com/puppy/viewtopic.php?t=76049l]RacyPy[/url]" puplet on Toshiba Tecra 8200. PIII, 256 MB RAM.
[url=http://raspberrypy.tumblr.com/]RaspberryPy[/url]: Lobster and I blog about the RPi.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#9 Post by disciple »

antiloquax wrote:I know that Arch Linux comes with Python 3 as default
I didn't notice it come with any Python... which is what I'd expect for "the Arch way" :)

Incidentally I think currently all the programs I have which use Python are using Python2... but I think there might be at least one I've built from the AUR to avoid the "Python" dependency of the official package.
Lobster wrote:As far as I know Python is available in the devx so you could use Glade as the GUI creation tool - again never found that straight forward.
Does that require PyGTK?
Does the devx include either Pyglade (or whatever it's called) or PyGTK?
Also available in the devx is the genie language which is python and BASIC like - but compiled . . .
http://puppylinux.org/wikka/ValaGenieintro
You might be interested in this thread, although it isn't about python and glade: http://www.murga-linux.com/puppy/viewto ... 277#603859
The thread is about the old version of the Glade designer, which supports code generation. But that post of mine has a link to a similar thing for Vala.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
antiloquax
Posts: 405
Joined: Fri 27 Jan 2012, 09:17

#10 Post by antiloquax »

disciple wrote: I didn't notice it come with any Python... which is what I'd expect for "the Arch way" :)
:D

I've just realised that the PET I made for Pygame does not work. I think you just have to do it like this:
1. Download Pygame 1.9.1.
2. Make sure you have SDL DEV package and your DEVX (for compiling).
3. When you have extracted the tarball, open a console in the directory and do this:

python3.1 config.py
2to3 setup.py -w
python3.1 setup.py build
python3.1 setup.py install
My System:Arch-Arm on RPi!
"[url=http://murga-linux.com/puppy/viewtopic.php?t=76049l]RacyPy[/url]" puplet on Toshiba Tecra 8200. PIII, 256 MB RAM.
[url=http://raspberrypy.tumblr.com/]RaspberryPy[/url]: Lobster and I blog about the RPi.

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#11 Post by Lobster »

Does that require PyGTK?
Does the devx include either Pyglade (or whatever it's called) or PyGTK?
As far as I am aware it only includes Python and also Idle (the editor) I seem to remember.
Tkinter requires the tkl language which is no longer standard in Puppy. Even with Tkl, the most I got it to do is some non functioning buttons - much as you have shown - unless linked to code this is of no use.
It was the jump from example to functioning GUI code that I can not achieve in Python.

I am game. Will try some more . . . :D
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
antiloquax
Posts: 405
Joined: Fri 27 Jan 2012, 09:17

#12 Post by antiloquax »

Lobster wrote:. Even with Tkl, the most I got it to do is some non functioning buttons - much as you have shown - unless linked to code this is of no use.
That's interesting ... I haven't got that far with learning the language yet - I'll see what happens.
mark
My System:Arch-Arm on RPi!
"[url=http://murga-linux.com/puppy/viewtopic.php?t=76049l]RacyPy[/url]" puplet on Toshiba Tecra 8200. PIII, 256 MB RAM.
[url=http://raspberrypy.tumblr.com/]RaspberryPy[/url]: Lobster and I blog about the RPi.

Post Reply