I think it is about time some of the local Torbay schools started to take me seriously with regard to my IT / Programming skills. To this end I will break from the current trend of not sharing code along with project screen shots.
I have written a GUI (Graphical User Interface) version of a Magic 8 program written by Tom Brough. Since my original version I have now added error checking. The complete how to for this and an explanation of how the program works can be found in a document I am working on, however I am sharing the source code below.
I am happy to work with schools on this and other projects, explain how everything works etc and hopefully help develop some high quality teaching resources. But I expect to get some sort of PAID employment for this.
The code for the magic 8 program GUI version is below.
#!/usr/bin/env python #Written by Tom Brough and Paul Sutton # -*- coding: utf-8 -*- so. #!/usr/bin/env python import random import Tkinter # note use of caps from Tkinter import * #set up window = Tk() window.title('Magic 8') window.geometry("300x100") #wxh window.resizable(0,0) RESPONSES = ["It is certain", "It is decidedly so", "Without a doubt", "Yes definitely", "You may rely on it", "As I see it yes", "Most likely", "Outlook good", "Yes", "Signs point to yes", "Reply hazy try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again", "Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful"] def response(): msg = "error : must be a text value" i = circletext.get() so. y = i.isdigit() l = len(circletext.get()) #print l if y == True or l == 0: circletext.insert(0,(msg)) else: x = random.choice(RESPONSES)s circletext2.delete(0, END) # clear prev output circletext2.insert(0,str(x)) # insert response #define labels - cannot share same name as function box1 = Label(window, text="Question: ") box2 = Label(window, text="Answer: ") Toggle #place labels box1.grid(row = 1, column = 1, padx = 5, pady = 5) box2.grid(row = 2, column = 1, padx = 5, pady = 5) #define entry box circleVar = StringVar() circletext = Entry(window, textvariable=circleVar) #define out box circleVar2 = StringVar() circletext2 = Entry(window, textvariable=circleVar2) #display boxes circletext.grid(row = 1, column = 2,) #question box circletext2.grid(row = 2, column = 2,) #response box #define buttons response = Button( window, text ='respomse', command=response) exitbtn = Button( window, text ='Exit', command=exit) #place buttons response.grid(row = 4, column = 1, padx = 1, pady = 1) exitbtn.grid(row = 4, column = 2, padx = 1, pady = 1) #display window window.mainloop() #while(True): # raw_input("Enter your questToggleion: ")
Program probably needs some more work but any code is like that, there is always a way to add new features or add better code.