Skip to content

Commit f2be707

Browse files
author
Belvedere Tiburon Library CoderDojo
committed
update files
1 parent 5760029 commit f2be707

File tree

7 files changed

+62
-63
lines changed

7 files changed

+62
-63
lines changed
277 Bytes
Binary file not shown.

__pycache__/screens.cpython-34.pyc

11.7 KB
Binary file not shown.

__pycache__/window.cpython-34.pyc

2.73 KB
Binary file not shown.

dist/LearnPythonWithPython.exe

23 KB
Binary file not shown.

screens.py

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,125 +5,123 @@ class Screen:
55
def __init__(self, title, showAs, func):
66
self.title = title
77
self.showAs = showAs
8-
self.screenFunc = func
8+
self.func = func
99

10-
class LessonScreen:
10+
class LessonScreen(Screen):
1111
def __init__(self, i, text, screenFunc):
1212
title = "Lesson "+str(i)+": "+text
1313
showAs = title
1414
func = screenFunc
1515
super(LessonScreen, self).__init__(title, showAs, func)
1616

17-
class ProjectScreen:
17+
class ProjectScreen(Screen):
1818
def __init__(self, unit, proj, partTitle, screenFunc):
1919
text = "Unit "+str(unit)+" - "+proj+": "+partTitle
2020
showAs = partTitle
2121
func = screenFunc
2222
super(ProjectScreen, self).__init(title, showAs, func)
2323

2424
class Screens(Window):
25-
homeBounds = "800x1000"
26-
screenBounds = "800x400"
2725

2826
def new_lesson(self, unit, screenNum):
2927
screenNum -= 1
28+
self.master.geometry(self.screenBounds)
3029
unitStr = "self.u"+str(unit)
31-
u = exec(unitStr)
32-
self.new()
33-
self.cenLbl(u[screenNum].text)
30+
u = eval(unitStr)
31+
self.new(1)
32+
self.cenLbl(u[screenNum].title)
3433
if screenNum > 0:
35-
prevBtn(u[screenNum-1].func)
34+
self.btnPrev(u[screenNum-1].func)
3635
if screenNum < len(u)-1:
37-
nextBtn(u[screenNum+1].func)
36+
self.btnNext(u[screenNum+1].func)
3837

3938
def __init__(self, master=None):
39+
self.homeBounds = "800x1000"
40+
self.screenBounds = "800x400"
41+
self.units = [
42+
43+
]
44+
self.u1 = [
45+
LessonScreen(1, "Setting up the IDE", self.idle),
46+
LessonScreen(2, "Basic syntax", self.syn),
47+
LessonScreen(3, "Variables", self.var),
48+
LessonScreen(4, "Data types", self.data_types),
49+
LessonScreen(5, "Hello, world!", self.hello_world),
50+
LessonScreen(6, "Input", self.inp),
51+
LessonScreen(7, "If statements", self.if_statement),
52+
LessonScreen(8, "Else and elif statements", self.else_elif),
53+
LessonScreen(9, "\"WHAT THE HECK IS A METHOD!?!?!?\" (your comments)", self.methods),
54+
LessonScreen(10, "A function. Ok? I will tell you what a function is.", self.functions)
55+
]
4056
super(Screens, self).__init__(master)
4157
self.master = master
4258
self.master.title("LearnPythonWithPython")
4359
self.pack(fill=BOTH, expand=1)
44-
self.u1 = [
45-
Screen(1, "Setting up the IDE", self.idle),
46-
Screen(2, "Basic syntax", self.syn),
47-
Screen(3, "Variables", self.var),
48-
Screen(4, "Data types", self.data_types),
49-
Screen(5, "Hello, world!", self.hello_world),
50-
Screen(6, "Input", self.inp),
51-
Screen(7, "If statements", self.if_statement),
52-
Screen(8, "Else and elif statements", self.else_elif),
53-
Screen(9, "\"WHAT THE HECK IS A METHOD!?!?!?\" (your comments)", self.methods)
54-
]
5560

5661
def s_init(self, unitNum):
57-
self.new(home=True)
62+
print("s_init")
63+
self.new(0)
5864
s = "self.unit_"+str(unitNum)+"()"
5965
exec(s)
6066
self.master.geometry(self.homeBounds)
6167

6268
def unit_1(self):
63-
for i in range(len(self.screens)):
69+
print("u1")
70+
for i in range(len(self.u1)):
6471
s = self.u1[i]
65-
self.cenBtn(s.showAs, lambda: self.goTo(s.func))
66-
67-
def goTo(self, func):
68-
self.master.geometry(screenBounds)
69-
func()
72+
self.cenBtn(s.showAs, s.func)
7073

7174
def idle(self):
72-
self.new_lesson(1)
75+
self.new_lesson(1, 1)
7376
self.multiLbl("Hello, and welcome to LearnPythonWithPython. Today we will be learning about how to set up the IDE called IDLE but ... come to think about it, you are viewing this application so you probably already have IDLE installed. See you later.")
7477

7578
def syn(self):
76-
self.new_lesson(2)
79+
self.new_lesson(1, 2)
7780
self.multiLbl("Congratulations! You've completed lesson 1. This is lesson 2. To see the basic syntax, look at the source code for this application.")
7881

7982
def var(self):
80-
self.new_lesson(3)
83+
self.new_lesson(1, 3)
8184
self.multiLbl("Just like literally every single coding language in the world (except for maybe like BASIC and Assembly) and for sure every C based coding language (hint hint: Python is a C-based language), there are variables. There are many different types of variables in Python. Some examples are booleans (coming from Boolean algebra), lambdas (from lambda calculus) and numbers (from litterally every single form of math). Unlike 6th grade math, 7th grade math, 8th grade math, 9th grade math (Algebra I), 10th grade math (Geometry), 11th grade math (Algebra II), 12th grade math(Trigonometry?), college math(Calculus, Linear algebra, etc, etc, etc, and etc.), and some high school and college science(physics), variables in coding can have names longer than 1 letter with subscript. The only downside is that it takes up memory, and it takes up soooo mmuch storage. Like entire bytes. Soooooooo much!!!")
8285

8386
def data_types(self):
84-
self.new_lesson(4)
87+
self.new_lesson(1, 4)
8588
self.multiLbl("As I said last lesson, variables can be mmmmmmaaaaaannnnnnyyyyyy different types of things. A variable can be an str which is an str-ing of text surrounded by quotes (e.g. \"Hello, world!\"), an int which is an int-eger (e.g. 42), a float which is a float-ing point number (e.g. 3.14159265358979323846264338327950288419716939937510), a boolean which is a boolean value (which is either True or False. I think it's False. Wait nevermind it's true.), an array which stores an array of values surrounded in brackets where all the values are seperated by ,s (e.g. [\"Why?\", \"Are we stronger than the elements?\", \"What's yellow and dangerous?\", \"What do you get when you multiply six by seven?\", \"How many Vogons does it take to change a lightbulb?\", \"How many roads must a man walk down?\", 42, True, [\"Waaaait... an array inside an array?\", \"that's cray-cray\"], \"Is the array done yet?\", False,...] you get the idea.), a dictionary which is basically a dictionary for variables (e.g. ages = {\"Bob\": 100, \"Me\": 11}) and sooooo on and soooo forth")
8689

8790
def hello_world(self):
88-
self.new_lesson(5)
91+
self.new_lesson(1, 5)
8992
self.multiLbl("Hello world programs are usually the first to be learned because they are so simple, but why do they make them so simple? Those programs could be made harder and more fun by just a little bit. First things first, you need to know what a hello world program looks like, so look in the console. Go on. I'm not going anywhere. You want to be able to do that? Well, that sucks for you. This lesson is not about hello world. It's about the base methods in Python. \"What's a method?\" I hear you typing in the comments. Well, I'm not telling you. And also I don't read the comments. So sucks for you.\nSo any ways, there are many base methods >:(don't even try asking):< such as print and input. Print prints text to the console. Input asks the user for input. That simple. Well not really. In print you have to put () after it because it's a *method* and inside those parentheses put what you want to say (HAS TO BE AN STR (can be a variable)), for example print(\"LearnPythonWithPython\") will print LearnPythonWithPython. Seriously. Try it. PRESS LE BUTTON!!!")
90-
code = """
91-
print("LearnPythonWithPython")
92-
"""
93+
code = """print("LearnPythonWithPython")"""
9394
self.cenBtn(code, lambda: exec(code))
9495
self.cenLbl("It's time for CHALLENGE TIME: Try to make a hello world program by declaring a variable called string and print()ing it")
9596

9697
def inp(self):
97-
self.new_lesson(6)
98+
self.new_lesson(1, 6)
9899
self.multiLbl("Hello, world! That last (mini) project was fun...ish. We want to make programs with UI! We want user input() ... i mean interface lol lmao rofl lellellellellelelelelelllelleleellelelelellelelel. so user \"interface\" as they call it is an interface where users interact. Hey! There's another possible name! User Interaction stuf! well anyways, let's get to the point. The input() method is a good starting point for UI. It allows the user to enter ... wait for it ... input()! Inside the parentheses thingies, you have to type in what ever you want the computer to ask you. For instance, press the button that has a line of code on it.")
99-
code = """
100-
inp = input("Enter your input here: ")
101-
print(inp)
102-
"""
100+
code = """inp = input("Enter your input here: ")
101+
print(inp)\t\t\t\t"""
103102
self.cenBtn(code, lambda: exec(code))
104103
self.cenLbl("Now you try to figure out a practical purpose for the input() method. Enter it in the comments (that I tooooootally read)")
105104

106105
def if_statement(self):
107-
self.new_lesson(7)
106+
self.new_lesson(1, 7)
108107
self.multiLbl("If statements determine *if* a condition (e.g. 1>2 is False and \"hello\" == \"hello\" is True) is True, then it does the stuff indented after the colon(:). One example is")
109-
code = """
110-
if True:
111-
\tprint("if True: \n\t\"is always evaluated\"")
112-
if False:
113-
\tprint("if False: \n\t\"is never evaluated\"")
114-
"""
115-
self.cenBtn(btnText, lambda: exec(code))
108+
code = """if True:\t\t\t\t\t
109+
\tprint("if True: is always evaluated")
110+
if False:\t\t\t\t\t
111+
\tprint("if False: is always evaluated")"""
112+
self.cenBtn(code, lambda: exec(code))
116113

117114
def else_elif(self):
118-
self.new_lesson(8)
115+
self.new_lesson(1, 8)
119116
self.multiLbl("\"But ... what if you want to test if something you just tested is not True? Do you need another if statement with (whatever condition) == False?\" I hear you commenting in the comment section. Well, the answer is NO STUPID!!! THIS IS PROGRAMMING!!! AND THIS LESSON EXISTS!!! LOOK AT THE TITLE!!! WHAT DID YOU THINK IT WOULD BE ABOUT??? The solution lies in else statements, which literally translate to ... you guessed it — else. You just type else: and then whatever the print(\"****\") you want if the condition you tested is false. \"But what if you want to have an if and else statement *inside* an else statement?\" The answer is THIS IS CODING YOU NOT SMART PERSON. And plus, it says it in the title. elif is short for else if which is short for else-erwise if this is true.")
120117

121118
def methods(self):
122-
self.new_lesson(9)
119+
self.new_lesson(1, 9)
123120
self.multiLbl("Now, we're finally going to answer that question: \"WHAT THE HECK IS A METHOD?!?!?!?!?!?!?!?!?!\" Geez. Stop commenting. ITS BAD 4 UR PUNCSHOOASHUN CUPZ LOC KEE AN SPELEENG. IT WILL TURN THE SQL DATABASE THAT I DON'T READ INTO A YOUTUBE COMMENTS! I LITTERALLY MAKE THE WORDS UR COMMENT HAS BEEN RECIEVED APPEAR EVEN IF I NEVER READ IT!!! SHOOT MY CUZ LUC KEE IZ BROCEN I M USING A MAC ALL MY TEXT IS NOW AND FOREVER CAPITALIZED :(:(:(:(:(:(:(")
124121
self.multiLbl("SO, ANYWAYS, A METHOD IS A FUNCTION INSIDE OF A CLASS. \"WHAT ARE FUNCTIONS AND CLASSES?\" YOU WILL FIND OUT NEXT LESSON.")
125122

126123
def functions(self):
127-
self.new_lesson(10)
128-
self.multiLbl("A function. Use def function_name:\n\t#insert_code_here to create a function and function_name() to call it.")
124+
self.new_lesson(1, 10)
125+
self.multiLbl("A function. Use:\n def function_name(args):\n\t#insert_code_here\n to create a function and function_name(args) to call it. You can have as many args as you want and they can be whatever you want. Be warned. Functions are eeeeevvvvveeeeerrrrryyyyywwwwwhhhhheeeeerrrrreeeee. Print is a function. Input is a function. If you look at the source code, you might see functions such as eval and exec. There are many other functions just 2 name a few.")
126+
129127

setup_exe.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from distutils import setup
1+
from distutils.core import setup
22
import py2exe
3-
import windows, screen
3+
import window, screens
44

55
setup(
6-
windows = [{
6+
console = [{
77
"script": "mainloop.py",
8+
"icon_resources": [(1, "pycon-icon.ico")],
89
"dest_base": "LearnPythonWithPython"
910
}]
1011
)

window.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Window(Frame):
44
def __init__(self, master=None):
55
super(Window, self).__init__()
6-
self.s_init()
6+
self.s_init(1)
77

88
def close_app(self):
99
self.master.destroy()
@@ -21,8 +21,8 @@ def choBtn(self, txt, func, x, y):
2121
def btnQuit(self):
2222
return self.choBtn("Quit", self.close_app, 0, 0)
2323

24-
def btnBack(self):
25-
return self.choBtn("Back", self.s_init, 0, 0)
24+
def btnBack(self, unit):
25+
return self.choBtn("Back", lambda: self.s_init(unit), 0, 0)
2626

2727
def btnNext(self, nextScreen):
2828
return Button(self, text="Next", command=nextScreen).place(relx=1.0, rely=1.0, anchor=SE)
@@ -39,12 +39,12 @@ def cenLbl(self, txt):
3939
return Label(self, text=txt).pack()
4040

4141
def multiLbl(self, txt):
42-
return Label(self, text=txt, anchor=W, wraplength=425).pack()
42+
return Label(self, text=txt, wraplength=750).pack(anchor=W)
4343

44-
def new(self, home=False):
44+
def new(self, unit):
4545
for widget in self.winfo_children():
4646
widget.destroy()
47-
if home == True:
47+
if unit == 0:
4848
self.btnQuit()
4949
else:
50-
self.btnBack()
50+
self.btnBack(unit)

0 commit comments

Comments
 (0)