Here is some of the code that I write for Technocamps
You may find these useful if you have been to one of our workshops
Magic 8 Ball
Version 1.0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <span class = "com" > #####################################################################</span><span class="pln"> < / span><span class = "com" > # Author : Robert Lutken #</span><span class="pln"> < / span><span class = "com" > # Date : 18/01/2016 #</span><span class="pln"> < / span><span class = "com" > # File : MagicEightBall.py #</span><span class="pln"> < / span><span class = "com" > # Purpose : Demonstration of IF statements in python #</span><span class="pln"> < / span><span class = "com" > # Version : 1.0 #</span><span class="pln"> < / span><span class = "com" > #####################################################################</span><span class="pln"> < / span><span class = "com" > # Use code from the Random Library (Someone else's code)</span><span class="pln"> < / span><span class = "kwd" > import < / span><span class = "pln" > random < / span><span class = "com" > #Define Computer's Answers </span><span class="pln"> ans1 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "Go For It!" < / span><span class = "pln" > ans2 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "No way!" < / span><span class = "pln" > ans3 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "I'm not sure!?" < / span><span class = "pln" > ans4 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "The universe states that is inconceivable" < / span><span class = "pln" > ans5 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "That is not possible" < / span><span class = "pln" > ans6 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "Yes." < / span><span class = "pln" > < / span><span class = "com" > # Generate a random number</span><span class="pln"> randomNumber < / span><span class = "pun" > = < / span><span class = "pln" > random< / span><span class = "pun" >.< / span><span class = "pln" >randint< / span><span class = "pun" >(< / span><span class = "lit" > 0 < / span><span class = "pun" >,< / span><span class = "lit" > 6 < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > #Output start prompt </span><span class="pln"> question < / span><span class = "pun" > = < / span><span class = "pln" > input < / span><span class = "pun" >(< / span><span class = "str" > "Please enter a question: " < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > # Calculate response</span><span class="pln"> < / span><span class = "kwd" > if < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 1 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans1 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 2 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans2 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 3 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans3 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 4 < / span><span class = "pun" >:< / span><span class = "pln" > anwer < / span><span class = "pun" > = < / span><span class = "pln" > ans4 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 5 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans5 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 6 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans6 < / span><span class = "kwd" > else < / span><span class = "pln" > < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans6 < / span><span class = "kwd" > print < / span><span class = "pln" > < / span><span class = "pun" >(< / span><span class = "str" > "You asked the computer:" < / span><span class = "pun" >,< / span><span class = "pln" > question< / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "kwd" > print < / span><span class = "pln" > < / span><span class = "pun" >(< / span><span class = "str" > "The computer says:" < / span><span class = "pun" >,< / span><span class = "pln" > answer< / span><span class = "pun" >)< / span><span class = "pln" > input < / span><span class = "pun" >(< / span><span class = "str" > "Press [Enter] to Exit:" < / span><span class = "pun" >)< / span><span class = "pln" > < / span> |
Version 1.1 – While Loops
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <span class = "com" > #########################################################################################</span><span class="pln"> < / span><span class = "com" > # Author : Robert Lutken #</span><span class="pln"> < / span><span class = "com" > # Date : 18/01/2016 #</span><span class="pln"> < / span><span class = "com" > # File : MagicEightBall.py #</span><span class="pln"> < / span><span class = "com" > # Purpose : Demonstration of While statements in python #</span><span class="pln"> < / span><span class = "com" > # Version : 1.1 #</span><span class="pln"> < / span><span class = "com" > ########################################################################################</span><span class="pln"> < / span><span class = "com" > # Use code from the Random Library (Someone else's code)</span><span class="pln"> < / span><span class = "kwd" > import < / span><span class = "pln" > random < / span><span class = "com" > #Define Computer's Answers </span><span class="pln"> ans1 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "Go For It!" < / span><span class = "pln" > ans2 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "No way!" < / span><span class = "pln" > ans3 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "I'm not sure!?" < / span><span class = "pln" > ans4 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "The universe states that is inconceivable" < / span><span class = "pln" > ans5 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "That is not possible" < / span><span class = "pln" > ans6 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "Yes." < / span><span class = "pln" > < / span><span class = "com" > # Set user input to 0 so we enter the loop</span><span class="pln"> usrInput < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "lit" > 0 < / span><span class = "pln" > < / span><span class = "com" > # Loop untill usrInput is not 0</span><span class="pln"> < / span><span class = "com" > # This says keep doing what ever is indented untill</span><span class="pln"> < / span><span class = "com" > # usrInput is EQUAL (==) to 0</span><span class="pln"> < / span><span class = "kwd" > while < / span><span class = "pln" > usrInput < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 0 < / span><span class = "pun" >:< / span><span class = "pln" > < / span><span class = "com" > # Generate a random number</span><span class="pln"> randomNumber < / span><span class = "pun" > = < / span><span class = "pln" > random< / span><span class = "pun" >.< / span><span class = "pln" >randint< / span><span class = "pun" >(< / span><span class = "lit" > 0 < / span><span class = "pun" >,< / span><span class = "lit" > 6 < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > #Output start prompt </span><span class="pln"> question < / span><span class = "pun" > = < / span><span class = "pln" > input < / span><span class = "pun" >(< / span><span class = "str" > "Please enter a question: " < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > # Calculate response</span><span class="pln"> < / span><span class = "kwd" > if < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 1 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans1 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 2 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans2 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 3 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans3 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 4 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans4 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 5 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans5 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 6 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans6 < / span><span class = "kwd" > else < / span><span class = "pln" > < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans6 < / span><span class = "com" > # Print answer</span><span class="pln"> < / span><span class = "kwd" > print < / span><span class = "pln" > < / span><span class = "pun" >(< / span><span class = "str" > "You asked the computer:" < / span><span class = "pun" >,< / span><span class = "pln" > question< / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "kwd" > print < / span><span class = "pln" > < / span><span class = "pun" >(< / span><span class = "str" > "The computer says:" < / span><span class = "pun" >,< / span><span class = "pln" > answer< / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > # Ask if user wants to quit</span><span class="pln"> usrInput < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "kwd" > int < / span><span class = "pun" >(< / span><span class = "pln" > input < / span><span class = "pun" >(< / span><span class = "str" > "Enter 1 to exit or 0 to continue:" < / span><span class = "pun" >))< / span><span class = "pln" > < / span><span class = "kwd" > print < / span><span class = "pln" > < / span><span class = "pun" >(< / span><span class = "str" > "Exiting...." < / span><span class = "pun" >)< / span> |
Version 1.2 – Functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <span class = "com" > #########################################################################################</span><span class="pln"> < / span><span class = "com" > # Author : Robert Lutken #</span><span class="pln"> < / span><span class = "com" > # Date : 18/01/2016 #</span><span class="pln"> < / span><span class = "com" > # File : MagicEightBall.py #</span><span class="pln"> < / span><span class = "com" > # Purpose : Demonstration of Functions in python #</span><span class="pln"> < / span><span class = "com" > # Version : 1.2 #</span><span class="pln"> < / span><span class = "com" > ########################################################################################</span><span class="pln"> < / span><span class = "com" > # Use code from the Random Library (Someone else's code)</span><span class="pln"> < / span><span class = "kwd" > import < / span><span class = "pln" > random < / span><span class = "com" > # Define a function that has a random number passed into it</span><span class="pln"> < / span><span class = "com" > # The function will calculate as normal then return the answer</span><span class="pln"> < / span><span class = "kwd" > def < / span><span class = "pln" > < / span><span class = "typ" >CalculateResponse< / span><span class = "pun" >(< / span><span class = "pln" >randomNumber< / span><span class = "pun" >):< / span><span class = "pln" > < / span><span class = "com" > # Calculate response</span><span class="pln"> < / span><span class = "kwd" > if < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 1 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans1 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 2 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans2 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 3 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans3 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 4 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans4 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 5 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans5 < / span><span class = "kwd" > elif < / span><span class = "pln" > randomNumber < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 6 < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans6 < / span><span class = "kwd" > else < / span><span class = "pln" > < / span><span class = "pun" >:< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > ans6 < / span><span class = "kwd" > return < / span><span class = "pln" > answer < / span><span class = "com" > #Define Computer's Answers </span><span class="pln"> ans1 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "Go For It!" < / span><span class = "pln" > ans2 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "No way!" < / span><span class = "pln" > ans3 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "I'm not sure!?" < / span><span class = "pln" > ans4 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "The universe states that is inconceivable" < / span><span class = "pln" > ans5 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "That is not possible" < / span><span class = "pln" > ans6 < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "str" > "Yes." < / span><span class = "pln" > < / span><span class = "com" > # Set user input to 0 so we enter the loop</span><span class="pln"> usrInput < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "lit" > 0 < / span><span class = "pln" > < / span><span class = "com" > # Loop untill usrInput is not 0</span><span class="pln"> < / span><span class = "com" > # This says keep doing what ever is indented untill</span><span class="pln"> < / span><span class = "com" > # usrInput is EQUAL (==) to 0</span><span class="pln"> < / span><span class = "kwd" > while < / span><span class = "pln" > usrInput < / span><span class = "pun" > = = < / span><span class = "pln" > < / span><span class = "lit" > 0 < / span><span class = "pun" >:< / span><span class = "pln" > < / span><span class = "com" > # Generate a random number</span><span class="pln"> randomNumber < / span><span class = "pun" > = < / span><span class = "pln" > random< / span><span class = "pun" >.< / span><span class = "pln" >randint< / span><span class = "pun" >(< / span><span class = "lit" > 0 < / span><span class = "pun" >,< / span><span class = "lit" > 6 < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > #Output start prompt </span><span class="pln"> question < / span><span class = "pun" > = < / span><span class = "pln" > input < / span><span class = "pun" >(< / span><span class = "str" > "Please enter a question: " < / span><span class = "pun" >)< / span><span class = "pln" > answer < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "typ" >CalculateResponse< / span><span class = "pun" >(< / span><span class = "pln" >randomNumber< / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > # Print answer</span><span class="pln"> < / span><span class = "kwd" > print < / span><span class = "pln" > < / span><span class = "pun" >(< / span><span class = "str" > "You asked the computer:" < / span><span class = "pun" >,< / span><span class = "pln" > question< / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "kwd" > print < / span><span class = "pln" > < / span><span class = "pun" >(< / span><span class = "str" > "The computer says:" < / span><span class = "pun" >,< / span><span class = "pln" > answer< / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > # Ask if user wants to quit</span><span class="pln"> usrInput < / span><span class = "pun" > = < / span><span class = "pln" > < / span><span class = "kwd" > int < / span><span class = "pun" >(< / span><span class = "pln" > input < / span><span class = "pun" >(< / span><span class = "str" > "Enter 1 to exit or 0 to continue:" < / span><span class = "pun" >))< / span><span class = "pln" > < / span><span class = "kwd" > print < / span><span class = "pln" > < / span><span class = "pun" >(< / span><span class = "str" > "Exiting...." < / span><span class = "pun" >)< / span> |
A-Level Mock Assessment
Video Tutorial for Task 1
Customers.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | <span class = "com" > # Only works in Python 3 (Created in 3.4.2)</span><span class="pln"> < / span><span class = "com" > # tkinter comes as part of the standard install - messagebox has to be imported explicitly</span><span class="pln"> < / span><span class = "str" > ''' Author : Robert Lutken Date : 24/03/2016 File : Customers.py Purpose : Tkinter Customer Information UI for Games Tech Ltd Mock Assesment Version : 1.0 ''' < / span><span class = "pln" > < / span><span class = "kwd" > from < / span><span class = "pln" > tkinter < / span><span class = "kwd" > import < / span><span class = "pln" > < / span><span class = "pun" > * < / span><span class = "pln" > < / span><span class = "kwd" > from < / span><span class = "pln" > tkinter < / span><span class = "kwd" > import < / span><span class = "pln" > messagebox < / span><span class = "str" > ''' SaveDetails -Gets the information from each of the Tkinter UI elements -Adds padding to the strings -Opens File to save -Writes newly padded details to the file -Closes the file Task : a) Add the appopriate number to pad the variables correctly for: LN38: ageSave LN42: dobSave LN46: postcodeSave LN48: telSave.ljust b) Add the filename to save customer details too. LN52: fileObject = open(...) ''' < / span><span class = "pln" > < / span><span class = "kwd" > def < / span><span class = "pln" > saveDetails< / span><span class = "pun" >()< / span><span class = "pln" > < / span><span class = "pun" >:< / span><span class = "pln" > < / span><span class = "com" > # for each field get the value from the screen and pad with spaces or chop if necessary</span><span class="pln"> nameSave< / span><span class = "pun" > = < / span><span class = "pln" > nameVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > nameSave < / span><span class = "pun" > = < / span><span class = "pln" > nameSave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "lit" > 30 < / span><span class = "pun" >)< / span><span class = "pln" > ageSave < / span><span class = "pun" > = < / span><span class = "pln" > ageVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > ageSave < / span><span class = "pun" > = < / span><span class = "pln" > ageSave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "str" > '''#...Add Correct Padding HERE!''' < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > #25/06/1993</span><span class="pln"> dobSave < / span><span class = "pun" > = < / span><span class = "pln" > dobVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > dobSave < / span><span class = "pun" > = < / span><span class = "pln" > dobSave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "str" > '''#...Add Correct Padding HERE!''' < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > #NP145SW</span><span class="pln"> postCodeSave < / span><span class = "pun" > = < / span><span class = "pln" > postCodeVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > postCodeSave < / span><span class = "pun" > = < / span><span class = "pln" > postCodeSave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "str" > '''#...Add Correct Padding HERE!''' < / span><span class = "pun" >)< / span><span class = "pln" > telSave < / span><span class = "pun" > = < / span><span class = "pln" > telVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > telSave < / span><span class = "pun" > = < / span><span class = "pln" > telSave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "str" > '''#...Add Correct Padding HERE!''' < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > #open the file to append - if it's not there it'll be created</span><span class="pln"> fileObject < / span><span class = "pun" > = < / span><span class = "pln" > open < / span><span class = "pun" >(< / span><span class = "str" > '''#... Open The Correct File HERE!''' < / span><span class = "pln" > < / span><span class = "pun" >,< / span><span class = "pln" > < / span><span class = "str" > "a" < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > # write to the file with a newline character at the end</span><span class="pln"> fileObject< / span><span class = "pun" >.< / span><span class = "pln" >write< / span><span class = "pun" >(< / span><span class = "pln" >nameSave < / span><span class = "pun" > + < / span><span class = "pln" > ageSave < / span><span class = "pun" > + < / span><span class = "pln" > dobSave < / span><span class = "pun" > + < / span><span class = "pln" > postCodeSave < / span><span class = "pun" > + < / span><span class = "pln" > telSave < / span><span class = "pun" > + < / span><span class = "pln" > < / span><span class = "str" > "\n" < / span><span class = "pun" >)< / span><span class = "pln" > fileObject< / span><span class = "pun" >.< / span><span class = "pln" >close< / span><span class = "pun" >()< / span><span class = "pln" > < / span><span class = "kwd" > return < / span><span class = "pln" > < / span><span class = "str" > ''' CountCustomers -Validates each of the UI Widgets -Opens customer details file -Cycles through each line of the file and places each line in recordVar -For each line it will check if the UI entry i.e. Rob is found on the line -Between characters [0:30] which is the padded string for the Name Entry -Adds up how many "Rob'</span><span class="pln">s</span><span class="str">" have been found -Displays message box to the user Task : a) Add the appopriate number to pad the variables correctly for: LN90: if len(ageSave) > 0: LN96: if len(dobSave) > 0: LN102: if len(postCodeSave) > 0: LN108: if len(dobSave) > 0: b) Add the correct validation to ensure that users are between the ages 1 and 99 LN113: if int(ageSave) > 0 or int(ageSave) < 0: c) Add the correct index for each record var when reading each line: LN153 - LN159 if ageSave in recordVar[ ] and not ageSave=="" : ''' def countCustomers() : CustomerCount = 0 CountNeeded = 0 #get the fields off the screen and validate them nameSave = nameVar.get() if len(nameSave) > 30 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> </span><span class=" typ ">Name</span><span class=" str ">" ) return ageSave = ageVar.get() '''#... if len(ageSave) > Add Correct Padding Offset HERE :''' if len (ageSave) > 0 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> </span><span class=" typ ">Age</span><span class=" str ">" ) return dobSave = dobVar.get() '''#... if len(dobSave) > Add Correct Padding Offset HERE':''' if len (dobSave) > 0 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> </span><span class=" typ ">Dob</span><span class=" str ">" ) return postCodeSave = postCodeVar.get() '''#... if len(postCodeSave) > Add Correct Padding Offset HERE :''' if len (postCodeSave) > 0 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> </span><span class=" typ ">PostCode</span><span class=" str ">" ) return telSave = telVar.get() '''#... if len(telSave) > Add Correct Padding Offset HERE :''' if len (telSave) > 0 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> </span><span class=" typ ">Tel</span><span class=" str ">" ) return '''if int(ageSave) > Add Correct Range HERE or int(ageSave) < Add Correct Age range HERE:''' if int (ageSave) > 0 or int (ageSave) < 0 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Please</span><span class=" pln "> enter a valid age</span><span class=" pun ">!</span><span class=" str ">" ) if not nameSave = = "" : CountNeeded + = 1 if not ageSave = = "" : CountNeeded + = 1 if not dobSave = = "" : CountNeeded + = 1 if not postCodeSave = = "" : CountNeeded + = 1 if not telSave = = "" : CountNeeded + = 1 if CountNeeded = = 0 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Please</span><span class=" pln "> enter something to count</span><span class=" pun ">!</span><span class=" pln "> \n</span><span class=" str ">" + int (CountNeeded) + "</span><span class=" pln "> are missing</span><span class=" pun ">!</span><span class=" str ">" ) return # try opening the file for reading try : fileObject = open ( "</span><span class=" pln ">customerdetails</span><span class=" pun ">.</span><span class=" pln ">txt</span><span class=" str ">" , "</span><span class=" pln ">r</span><span class=" str ">" ) # if it's not there then say except IOError: messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">No</span><span class=" pln "> file to read</span><span class=" str ">" ) # if we did open it then let's carry on! else : while True : CountGot = 0 recordVar = fileObject.readline() # Python keeps reading till EOF then returns a blank if recordVar = = "": fileObject.close() break if nameSave in recordVar[ 0 : 30 ] and not nameSave = = "" : CountGot + = 1 if ageSave in recordVar[ ''' Add Correct Index HERE''' ] and not ageSave = = "" : CountGot + = 1 if dobSave in recordVar[ ''' Add Correct Index HERE''' ] and not dobSave = = "": CountGot + = 1 if postCodeSave in recordVar[ ''' Add Correct Index HERE''' ] and not postCodeSave = = "": CountGot + = 1 if telSave in recordVar[ ''' Add Correct Index HERE''' ] and not telSave = = "": CountGot + = 1 if CountGot = = CountNeeded: CustomerCount + = 1 messagebox.showinfo( "</span><span class=" typ ">Information</span><span class=" str ">" , str (CustomerCount) + "</span><span class=" pln "> </span><span class=" typ ">Customer</span><span class=" pln "> found</span><span class=" pun ">.</span><span class=" str ">" ) return ''' MakeWindow -Creates global variables for each of the reqiured fields -Sets up Tkinter Window -Creates Labels and Entry Widgets -Adds two buttons and Registers the correct callbacks a) Add Correct Function Command to Buttons LN238 - 239: b1= Button(frame2, text="</span><span class="pln"> </span><span class="typ">Save</span><span class="pln"> </span><span class="str">", command= ) ''' def makeWindow(): #declared my globals here as this is the 1st routine called # the other routines have to be in front of this one as they get called by it # and the parser would get upset if they weren't there #Name #Age #DOB #PostCode #Tel global nameVar,ageVar,dobVar,postCodeVar,telVar #here's my window win = Tk() win.wm_title( "</span><span class=" typ ">Games</span><span class=" pln "> </span><span class=" typ ">Tech</span><span class=" pln "> </span><span class=" typ ">Ltd</span><span class=" str ">" ) #split into two sections then further split into a grid frame1 = Frame(win) frame1.pack() Label(frame1, text = "</span><span class=" typ ">Customer</span><span class=" pln "> </span><span class=" typ ">Details</span><span class=" str ">" , font = ( "</span><span class=" typ ">Helvetica</span><span class=" pln "> </span><span class=" lit ">12</span><span class=" pln "> bold</span><span class=" str ">" )).grid(row = 0 , column = 0 ) Label(frame1, text = "</span><span class=" typ ">Name</span><span class=" str ">" ).grid(row = 1 , column = 0 , sticky = W) # Setup entry widget for NAME nameVar = StringVar() nameEntry = Entry(frame1, textvariable = nameVar) # Set where text is saved nameEntry.grid(row = 1 ,column = 1 ,sticky = W) # Label for Age Label(frame1, text = "</span><span class=" typ ">Age</span><span class=" str ">" ).grid(row = 2 , column = 0 , sticky = W) # Setup entry widget for AGE ageVar = StringVar() ageEntry = Entry(frame1, textvariable = ageVar) ageEntry.grid(row = 2 ,column = 1 ,sticky = W) # Label for DOB Label(frame1, text = "</span><span class=" typ ">Date</span><span class=" pln "> of </span><span class=" typ ">Birth</span><span class=" str ">" ).grid(row = 3 , column = 0 , sticky = W) # Setup entry for DateOfBirth dobVar = StringVar() dobEntry = Entry(frame1, textvariable = dobVar) dobEntry.grid(row = 3 ,column = 1 ,sticky = W) # Label for POSTCODE Label(frame1, text = "</span><span class=" typ ">Post</span><span class=" pln "> </span><span class=" typ ">Code</span><span class=" str ">" ).grid(row = 4 , column = 0 , sticky = W) postCodeVar = StringVar() # Setup entry for POSTCODE postCodeEntry = Entry(frame1, textvariable = postCodeVar) postCodeEntry.grid(row = 4 ,column = 1 ,sticky = W) # Label for Telephone Label(frame1, text = "</span><span class=" typ ">Telephone</span><span class=" str ">" ).grid(row = 5 , column = 0 , sticky = W) # Setup entry for Telephone telVar = StringVar() telEntry = Entry(frame1, textvariable = telVar) telEntry.grid(row = 5 ,column = 1 ,sticky = W) frame2 = Frame(win) frame2.pack() # build my buttons in the other frame then pack them side by side b1 = Button(frame2, text = "</span><span class=" pln "> </span><span class=" typ ">Save</span><span class=" pln "> </span><span class=" str ">" , command = '''Add Funciton To Call Here''' ) b2 = Button(frame2, text = "</span><span class=" pln "> </span><span class=" typ ">Count</span><span class=" pln "> </span><span class=" str ">" , command = '''Add Funciton To Call Here''' ) b1.pack(side = LEFT); b2.pack(side = LEFT) return win #this is the main program! win = makeWindow() win.mainloop() < / span> |
Video Tutorial for Part 2
Games.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | <span class = "com" > # Only works in Python 3 (Created in 3.4.2)</span><span class="pln"> < / span><span class = "com" > # tkinter comes as part of the standard install - messagebox has to be imported explicitly</span><span class="pln"> < / span><span class = "str" > ''' Author : Robert Lutken Date : 28/04/2016 File : Games.py Purpose : Tkinter Games Information UI for Games Tech Ltd Mock Assesment Version : 1.0 ''' < / span><span class = "pln" > < / span><span class = "kwd" > from < / span><span class = "pln" > tkinter < / span><span class = "kwd" > import < / span><span class = "pln" > < / span><span class = "pun" > * < / span><span class = "pln" > < / span><span class = "kwd" > from < / span><span class = "pln" > tkinter < / span><span class = "kwd" > import < / span><span class = "pln" > messagebox < / span><span class = "str" > ''' SaveDetails -Gets the information from each of the Tkinter UI elements -Adds padding to the strings -Opens File to save -Writes newly padded details to the file -Closes the file ''' < / span><span class = "pln" > < / span><span class = "kwd" > def < / span><span class = "pln" > saveGame< / span><span class = "pun" >()< / span><span class = "pln" > < / span><span class = "pun" >:< / span><span class = "pln" > < / span><span class = "com" > # for each field get the value from the screen and pad with spaces or chop if necessary</span><span class="pln"> titleSave < / span><span class = "pun" > = < / span><span class = "pln" > titleVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > titleSave < / span><span class = "pun" > = < / span><span class = "pln" > titleSave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "lit" > 30 < / span><span class = "pun" >)< / span><span class = "pln" > priceSave < / span><span class = "pun" > = < / span><span class = "pln" > priceVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > priceSave < / span><span class = "pun" > = < / span><span class = "pln" > priceSave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "lit" > 3 < / span><span class = "pun" >)< / span><span class = "pln" > quantitySave < / span><span class = "pun" > = < / span><span class = "pln" > quantityVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > quantitySave < / span><span class = "pun" > = < / span><span class = "pln" > quantitySave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "lit" > 3 < / span><span class = "pun" >)< / span><span class = "pln" > pegiSave < / span><span class = "pun" > = < / span><span class = "pln" > pegiVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > pegiSave < / span><span class = "pun" > = < / span><span class = "pln" > pegiSave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "lit" > 3 < / span><span class = "pun" >)< / span><span class = "pln" > genreSave < / span><span class = "pun" > = < / span><span class = "pln" > genreVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > genreSave < / span><span class = "pun" > = < / span><span class = "pln" > genreSave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "lit" > 20 < / span><span class = "pun" >)< / span><span class = "pln" > publisherSave < / span><span class = "pun" > = < / span><span class = "pln" > publisherVar< / span><span class = "pun" >.< / span><span class = "kwd" >get< / span><span class = "pun" >()< / span><span class = "pln" > publisherSave < / span><span class = "pun" > = < / span><span class = "pln" > publisherSave< / span><span class = "pun" >.< / span><span class = "pln" >ljust< / span><span class = "pun" >(< / span><span class = "lit" > 30 < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > #open the file to append - if it's not there it'll be created</span><span class="pln"> fileObject < / span><span class = "pun" > = < / span><span class = "pln" > open < / span><span class = "pun" >(< / span><span class = "str" > "GameStock.txt" < / span><span class = "pun" >,< / span><span class = "str" > "a" < / span><span class = "pun" >)< / span><span class = "pln" > < / span><span class = "com" > # write to the file with a newline character at the end</span><span class="pln"> fileObject< / span><span class = "pun" >.< / span><span class = "pln" >write< / span><span class = "pun" >(< / span><span class = "pln" >titleSave < / span><span class = "pun" > + < / span><span class = "pln" > priceSave < / span><span class = "pun" > + < / span><span class = "pln" > quantitySave < / span><span class = "pun" > + < / span><span class = "pln" > pegiSave < / span><span class = "pun" > + < / span><span class = "pln" > genreSave < / span><span class = "pun" > + < / span><span class = "pln" > publisherSave < / span><span class = "pun" > + < / span><span class = "pln" > < / span><span class = "str" > "\n" < / span><span class = "pun" >)< / span><span class = "pln" > fileObject< / span><span class = "pun" >.< / span><span class = "pln" >close< / span><span class = "pun" >()< / span><span class = "pln" > < / span><span class = "kwd" > return < / span><span class = "pln" > < / span><span class = "str" > ''' CountCustomers -Validates each of the UI Widgets -Opens customer details file -Cycles through each line of the file and places each line in recordVar -For each line it will check if the UI entry i.e. Rob is found on the line -Between characters [0:30] which is the padded string for the Name Entry -Adds up how many "Rob'</span><span class="pln">s</span><span class="str">" have been found -Displays message box to the user ''' def countStock() : CustomerCount = 0 CountNeeded = 0 #get the fields off the screen and validate them titleSave = titleVar.get() if len (titleSave) > 30 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> </span><span class=" typ ">Title</span><span class=" str ">" ) return priceSave = priceVar.get() if len (priceSave) > 3 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> price</span><span class=" str ">" ) return quantitySave = quantityVar.get() if len (quantitySave) > 3 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> </span><span class=" typ ">Quantity</span><span class=" str ">" ) return pegiSave = pegiVar.get() if len (pegiSave) > 3 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> pegi</span><span class=" str ">" ) return genreSave = genreVar.get() if len (genreSave) > 20 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> genre</span><span class=" str ">" ) return publisherSave = publisherVar.get() if len (publisherSave) > 30 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Too</span><span class=" pln "> many characters </span><span class=" kwd ">in</span><span class=" pln "> publisher</span><span class=" str ">" ) return if not titleSave = = "" : CountNeeded + = 1 if not priceSave = = "" : CountNeeded + = 1 if not quantitySave = = "" : CountNeeded + = 1 if not pegiSave = = "" : CountNeeded + = 1 if not genreSave = = "" : CountNeeded + = 1 if not publisherSave = = "" : CountNeeded + = 1 if CountNeeded = = 0 : messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">Please</span><span class=" pln "> enter something to count</span><span class=" pun ">!</span><span class=" pln "> \n</span><span class=" str ">" + int (CountNeeded) + "</span><span class=" pln "> are missing</span><span class=" pun ">!</span><span class=" str ">" ) return # try opening the file for reading try : fileObject = open ( "</span><span class=" typ ">GameStock</span><span class=" pun ">.</span><span class=" pln ">txt</span><span class=" str ">" , "</span><span class=" pln ">r</span><span class=" str ">" ) # if it's not there then say except IOError: messagebox.showerror( "</span><span class=" typ ">Error</span><span class=" str ">" , "</span><span class=" typ ">No</span><span class=" pln "> file to read</span><span class=" str ">" ) # if we did open it then let's carry on! else : while True : CountGot = 0 recordVar = fileObject.readline() # Python keeps reading till EOF then returns a blank if recordVar = = "": fileObject.close() break if titleSave in recordVar[ 0 : 30 ] and not titleSave = = "" : CountGot + = 1 if priceSave in recordVar[ 30 : 33 ] and not priceSave = = "" : CountGot + = 1 if quantitySave in recordVar[ 33 : 36 ] and not quantitySave = = "": CountGot + = 1 if pegiSave in recordVar[ 36 : 39 ] and not pegiSave = = "": CountGot + = 1 if genreSave in recordVar[ 39 : 59 ] and not genreSave = = "": CountGot + = 1 if publisherSave in recordVar[ 59 : 89 ] and not publisherSave = = "": CountGot + = 1 if CountGot = = CountNeeded: CustomerCount + = 1 messagebox.showinfo( "</span><span class=" typ ">Information</span><span class=" str ">" , str (CustomerCount) + "</span><span class=" pln "> </span><span class=" typ ">Customer</span><span class=" pln "> found</span><span class=" pun ">.</span><span class=" str ">" ) return ''' MakeWindow -Creates global variables for each of the reqiured fields -Sets up Tkinter Window -Creates Labels and Entry Widgets -Adds two buttons and Registers the correct callbacks ''' def makeWindow(): #declared my globals here as this is the 1st routine called # the other routines have to be in front of this one as they get called by it # and the parser would get upset if they weren't there global titleVar,priceVar,quantityVar,pegiVar,genreVar,publisherVar #here's my window win = Tk() win.wm_title( "</span><span class=" typ ">Games</span><span class=" pln "> </span><span class=" typ ">Tech</span><span class=" pln "> </span><span class=" typ ">Ltd</span><span class=" str ">" ) #split into two sections then further split into a grid frame1 = Frame(win) frame1.pack() Label(frame1, text = "</span><span class=" typ ">Game</span><span class=" pln "> </span><span class=" typ ">Stock</span><span class=" str ">" , font = ( "</span><span class=" typ ">Helvetica</span><span class=" pln "> </span><span class=" lit ">12</span><span class=" pln "> bold</span><span class=" str ">" )).grid(row = 0 , column = 0 ) Label(frame1, text = "</span><span class=" typ ">Game</span><span class=" pln "> </span><span class=" typ ">Title</span><span class=" str ">" ).grid(row = 1 , column = 0 , sticky = W) # Setup entry widget for Title titleVar = StringVar() titleVar = Entry(frame1, textvariable = titleVar) # Set where text is saved titleVar.grid(row = 1 ,column = 1 ,sticky = W) # Label for Price Label(frame1, text = "</span><span class=" typ ">Price</span><span class=" str ">" ).grid(row = 2 , column = 0 , sticky = W) # Setup entry widget for price priceVar = StringVar() priceVar = Entry(frame1, textvariable = priceVar) priceVar.grid(row = 2 ,column = 1 ,sticky = W) # Label for quantity Label(frame1, text = "</span><span class=" typ ">Quantity</span><span class=" str ">" ).grid(row = 3 , column = 0 , sticky = W) # Setup entry for DateOfBirth quantityVar = StringVar() quantityVar = Entry(frame1, textvariable = quantityVar) quantityVar.grid(row = 3 ,column = 1 ,sticky = W) # Label for Pegi Label(frame1, text = "</span><span class=" typ ">Pegi</span><span class=" str ">" ).grid(row = 4 , column = 0 , sticky = W) pegiVar = StringVar() # Setup entry for pegi pegiVar = Entry(frame1, textvariable = pegiVar) pegiVar.grid(row = 4 ,column = 1 ,sticky = W) # Label for Genre Label(frame1, text = "</span><span class=" typ ">Genre</span><span class=" str ">" ).grid(row = 5 , column = 0 , sticky = W) # Setup entry for Genre genreVar = StringVar() genreVar = Entry(frame1, textvariable = genreVar) genreVar.grid(row = 5 ,column = 1 ,sticky = W) # Label for Publisher Label(frame1, text = "</span><span class=" typ ">Publisher</span><span class=" str ">" ).grid(row = 6 , column = 0 , sticky = W) # Setup entry for Publisher publisherVar = StringVar() publisherVar = Entry(frame1, textvariable = publisherVar) publisherVar.grid(row = 6 ,column = 1 ,sticky = W) frame2 = Frame(win) frame2.pack() # build my buttons in the other frame then pack them side by side b1 = Button(frame2, text = "</span><span class=" pln "> </span><span class=" typ ">Save</span><span class=" pln "> </span><span class=" str ">" , command = saveGame) b2 = Button(frame2, text = "</span><span class=" pln "> </span><span class=" typ ">Count</span><span class=" pln "> </span><span class=" str ">" , command = countStock) b1.pack(side = LEFT); b2.pack(side = LEFT) return win #this is the main program! win = makeWindow() win.mainloop()< / span> |