Libraries & Tkinter


In the first week, you were introduced to state. In the second week, you were introduced to iteration, one of the more difficult programming constructs to grasp. In the third week, we discussed another programming construct: selection. In week four, we reinforced these topics while incorporating file handling. In week five, we used functions to produce organised, maintainable solutions. This week, we have started to look at creating programs that use graphics.

In this week's lab, we will use Tkinter, the GUI framework built into the Python standard library, to create a simple noughts and crosses game.

If you think you can build this game without assistance, try this now. Use the images in the images.zip (Click here to download!) file to represent empty squares, squares selected by each player and a 'Winner' screen.

If you would like some assistance, then work through this lab script. By the end, you will have created your own noughts and crosses game!

image





Click here to go to the COMP16321 Blackboard page


Click anywhere to close this video

Contents



Introduction

Task 1 - Tkinter

Task 2 – Importing our Graphics

Task 3 – Creating the Initial State

Task 4 – Event Handling

Task 5 - Taking Turns

Task 6 - Check for a Win

Conclusion


Green = Current Page

Click anywhere to close this overlay

Topics Covered in this Lab



1. Tkinter basics (Tk() function, mainloop())

2. PhotoImage function (loading images)

3. Button function

4. place function

5. Lambda functions

6. messagebox functions

7. 2D arrays

8. Iteration (While and For)

9. Array operations



Click anywhere to close this overlay

Lab Key



Notes – #FF6F61

Videos – #34568B

Code Examples – #009B77

Downloads - #C3447A

Internal Link (University Resources) – #955251

External Link (Non-University Resources)– #EFC050

Other - #660099



Click anywhere to close this overlay