Skip to content

Commit 2e5998f

Browse files
authored
Update screens.py
1 parent 2b2f4dd commit 2e5998f

File tree

1 file changed

+54
-9
lines changed

1 file changed

+54
-9
lines changed

screens.py

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ def new_lesson(self, unit, screenNum):
3838
def __init__(self, master=None):
3939
self.homeBounds = "800x1000"
4040
self.screenBounds = "800x400"
41-
self.units = [
42-
43-
]
4441
self.u1 = [
4542
LessonScreen(1, "Setting up the IDE", self.idle),
4643
LessonScreen(2, "Basic syntax", self.syn),
@@ -51,25 +48,45 @@ def __init__(self, master=None):
5148
LessonScreen(7, "If statements", self.if_statement),
5249
LessonScreen(8, "Else and elif statements", self.else_elif),
5350
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)
51+
LessonScreen(10, "A function. Ok? I will tell you what a function is.", self.functions),
52+
LessonScreen(11, "I told you. Object oriented programming is functions. Well, sort of.", self.oop)
53+
]
54+
PROJ = "Battleship"
55+
self.p1 = [
56+
ProjectScreen(1, PROJ, "What you're building", None),
57+
ProjectScreen(1, PROJ, "An empty list", None),
58+
ProjectScreen(1, PROJ, "Making the board", None),
59+
ProjectScreen(1, PROJ, "Printing the board", None),
60+
ProjectScreen(1, PROJ, "Hiding the ship", None)
5561
]
5662
super(Screens, self).__init__(master)
5763
self.master = master
5864
self.master.title("LearnPythonWithPython")
5965
self.pack(fill=BOTH, expand=1)
6066

6167
def s_init(self, unitNum):
62-
print("s_init")
68+
self.new(0)
69+
s = "self.unit_"+str(unitNum)+"()"
70+
exec(s)
71+
self.master.geometry(self.homeBounds)
72+
73+
def p_init(self, unitNum):
6374
self.new(0)
6475
s = "self.unit_"+str(unitNum)+"()"
6576
exec(s)
6677
self.master.geometry(self.homeBounds)
6778

6879
def unit_1(self):
69-
print("u1")
70-
for i in range(len(self.u1)):
71-
s = self.u1[i]
80+
for s in self.u1:
7281
self.cenBtn(s.showAs, s.func)
82+
self.cenBtn("Unit project: Battleship", lambda: self.p_init(1))
83+
self.cenBtn("Unit 2: Turtle graphics", None) #s_init(2)
84+
85+
def proj_1(self):
86+
for s in self.p1:
87+
self.cenBtn(s.showAs, s.func)
88+
self.cenBtn("Back to unit 1", lambda: self.s_init(1))
89+
self.cenBtn("Unit 2: Turtle graphics", None) #s_init(2)
7390

7491
def idle(self):
7592
self.new_lesson(1, 1)
@@ -117,11 +134,39 @@ def else_elif(self):
117134

118135
def methods(self):
119136
self.new_lesson(1, 9)
120-
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 :(:(:(:(:(:(:(")
137+
self.multiLbl("Now, we're finally going to answer that question: \"WHAT THE HECK IS A METHOD?!?!?!?!?!?!?!?!?!\" Geez. Stop commenting. ITZ BAD 4 UR PUNCSHOOASHUN CUPZ LOC KEE AN SPILEENG. 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 CUPZ LUC KEE IZ BROCEN I M USING A MAC ALL MY TEXT IS NOW AND FOREVER CAPITALIZED :(:(:(:(:(:(:(")
121138
self.multiLbl("SO, ANYWAYS, A METHOD IS A FUNCTION INSIDE OF A CLASS. \"WHAT ARE FUNCTIONS AND CLASSES?\" YOU WILL FIND OUT NEXT LESSON.")
122139

123140
def functions(self):
124141
self.new_lesson(1, 10)
125142
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.")
143+
144+
def oop(self):
145+
self.new_lesson(1, 11)
146+
self.multiLbl("You thought this lesson was going to be about classes? Ha! weeeelllllll, technically object oriented programming is classes. You see, a class has the basic methods and variables. An object is one version of a class. Let me explain and show you the syntax for a class at the same time by making a student class. I'll show you how.")
147+
code = """class Student:\t\t\t
148+
\tdef __init__(self, name, grade, gpa):\t
149+
\t\tself.name = name\t\t\t
150+
\t\tself.grade = grade\t\t\t
151+
\t\tself.gpa = gpa\t\t\t\t\t
152+
\tdef __repr__(self):\t\t\t
153+
\t\tprint(self.name+" has been in school for "+str(grade+1)+" years and his gpa is "+str(gpa)
154+
155+
billy = Student(\"Billy Bob Joe\", 5, 3.95)
156+
print(billy)"""
157+
self.cenBtn(code, lambda: exec(code))
158+
self.cenLbl("Two underscores signify a special keyword, and in the case of a class, it's usually a method name. The __init__ method is run as soon as the object is initialized, and it takes in self and whatever other arguments you want it to. Self refers to the class. The __repr__ and __str__ methods are what happen when you want it to be a string, __repr__ is like the official one and __str__ is called when you use str(object_name). You also have __del__ and __call__ and many, many more. You can also create methods but the first argument is always self and to run it from another method in the class, you have to do self.method_name or you can run it like ObjectName.method_name. You can also have static methods which are called by ClassName.method_name(args) and don't have a self. To define a static method, you do @staticmethod above the line with the method.")
126159

160+
def loops(self):
161+
self.new_lesson(1, 12)
162+
self.multiLbl("I'm doing this out of order but who cares. A loop is something that repeats. There are two types of loops. A for loop and a while loop. This should show you the difference")
163+
code = """for item in ["Hello,", "World!", "foo", "bar"]:
164+
\tprint(item)"""
165+
self.cenBtn(code, lambda: exec(code))
166+
code = """i = 0
167+
while i < 4:
168+
\tprint(i)
169+
i += 1"""
170+
self.cenBtn(code, lambda: exec(code))
171+
self.multiLbl("So as you can see, a for loop loops for every item in a list and a while loop repeats while a condition is true. For for loops, a function that is commonly used is range(n). Range makes a list of numbers between 0 (inclusive) and n (exclusive). So range(3) returns [0, 1, 2] and range(1) returns [0]. If you're using for with a dictionary, for thing in dict will make thing the key but for key, value in dict will have key as the key and value as the value. Mind blown. A while loop will run while the condition is True.")
127172

0 commit comments

Comments
 (0)