This is another little idea I have found while researching CoderDojo.
The next step to take should always be as small as possible.
– Yes, as small as possible.
In other words, when you are writing some code, test whether or not it does what you expect. If something isn’t right, fix it before moving on.
When you create a GUI, you are basically making a window with a grid in it. You decide where to position the widgets (labels, text boxes, buttons etc.) inside the grid and create them accordingly.
# gui1.py : demonstrates the grid in a GUI
# Import the Tk gui-making features
from tkinter import *
# create the “root” window – within which
# everything else will be built.
root = Tk()
app = Frame(root)
# setting up the GUI
# make some buttons
bttn1 = Button(app, text = “0,0”)
bttn1.grid(row = 0, column = 0)
bttn2 = Button(app, text = “0,1”)
bttn2.grid(row = 0, column = 1)
bttn3 = Button(app, text = “0,2”)
bttn3.grid(row = 0, column = 2)
bttn4 = Button(app, text = “1,0”)
bttn4.grid(row = 1, column = 0)
bttn5 = Button(app, text = “1,1”)
bttn5.grid(row = 1, column = 1)
bttn6 = Button(app, text = “1,2”)
bttn6.grid(row = 1, column = 2)
bttn7 = Button(app, text = “2,0”)
bttn7.grid(row = 2, column = 0)
bttn8 = Button(app, text = “2,1”)
bttn8.grid(row = 2, column = 1)
bttn9 = Button(app, text = “2,2”)
bttn9.grid(row = 2, column = 2)
# Start the main-loop (like in a game).
Alternative: You can download a program that does this (and a little bit more) here. Have a look at the code and make some changes – (eg, change what is printed when the button is clicked).
Hopefully this will help you to visualise the way we are creating the GUI for lovegui.py.
If you want, you can cut and paste this code into a new file in Python IDLE and check out how it works and see what happens if you make some changes.
Moved from top of post!
I’m keen for you to have a go at pair programming this week. The basic idea is that two people use one computer. You could compare it to flying a plane or driving a rally car. One person is “driving”, the other is “co-pilot”. The driver will type the code and operate the computer, the co-pilot will stay focused, read the code, spot errors and offer suggestions. As I have mentioned, this approach is used in “real” software development. If you want to read more, you can look at this webpage: Pair Programming.
Pair Programming is also part of the methodology of the CoderDojo movement. You might be interested in reading more about this also. It was started in Ireland by a Sixth-former who was keen to help young people to learn programming.
We’ve also been discussing the skills that we use when programming. If you are interested in what sort of skills programming develops, you might want to look at this page (from Learn Python The Hard Way). The author does a good job of explaining why excellent literacy skills are important for coders.
I’m haven’t got time today to write very much on this blog. So …
Here’s a text file you can download which has a Python program that uses a few of the different ways that we can work with strings.
What I’d like you to do is to edit this with IDLE. Make some changes and have a play with the way the different printing commands and options work.
Things to try:
See if you can use the multi-line printing approach to make some ascii art.
Then you could try wrting a program that asks the user a series of questions and then prints output which is formatted in an interesting way.
Can you use these methods to create a table with headings and neat layout?
I thought today we’d have a look at some HTML and how to make simple web-pages!
HTML (or Hypertext Markup Language) was created by Tim Berners-Lee, the scientist who created the World Wide Web. The first version of HTML was published in June 1993.
I’m sure many of you will have made websites before, but it’s likely that you will have used a web-design package like “FrontPage” or “Dreamweaver” that allows you to build pages without actually typing in the HTML tags.
First, I’d like you to go to this page and have a look at an extremely simple web-page.
I’ll explain here as well, just in case things go wrong :).
Open “Notepad” (we don’t want to use a Word-processor as that will add formatting and mess up our HTML).
Save it as “index.html”.
For some reason the school computers don’t let you view the source of web-pages. I am going to make a sheet with some of the simple html tags I used on the two web-pages you can see here.
If you get finished, I’d like you to do some research into Google’s Summer of Code. Maybe this is something you’d like to do, when you are a bit older (it’s for over-18s).