Home Year 7 Year 8 Year 9 GCSE A-Level

MR MAKEPEACE.NET

Python GUI    Tkinter

First program

from tkinter import *


''' creating a blank window'''

root = Tk()


''' add text'''

label1 = Label(root,text="hello")

''' put it in the first place in root'''

label1.pack()


''' keep root open - don't close after running'''

root.mainloop()



We start making some GUIs - its way cooler than before. Basically, Tkinter is an object orientated toolkit for making graphical programs


Widgets and layout


Tkinter has loads of pre made classes of different widgets - here is a list of them and how to use them  We will start with just the following


Widget/ object

Description

Example

Label

A piece of text or image(usually doesn't do anything)

label1 = Label(root, text = “hello world”)

Button

A button (usually when you press it it invokes a command which is linked to a function)

Video

Entry

Text entry box


Frame

Simple layout


Grid

Better layout with rows and columns

Video

Own program - Joke machine (Homework) - sheet

  1. Make a class Jokes that holds three  jokes in a list variable
  2. Make an init function for the jokes class that sets up a GUI with a label for the title, a label that will show a joke and a button that says “Get Joke”  
  3. Make a function that prints a random joke to the shell (not the GUI just yet)
  4. Make the command of the button the function to print the joke.
  5. Adjust the function so that it changes the label on the GUI rather print to shell (use the config() function to do this)
  6. Add an entry widget and another button that append jokes written into the  to the entry widget into the list of joke variable
  7. Improve the appearance and layout / add images (use forward slash when specifying the path name) this website may help



GCSE level 3( E)- Text base that out put a random joke from a list in a shell

GCSE level 4( D)- Text base that out put a random joke from a list in a shell

GCSE level 5( C+)- GUI base that outputs a random joke from a list in a GUI

GCSE level6(B)- GUI base that outputs a random joke from a list in a GUI with something extra / almost working

GCSE level 7 (A)- GUI base that outputs a random joke from a list in a GUI and allows jokes to be added via the GUI

GCSE level 8 /9 (A*)- GUI base that outputs a random joke from a list in a GUI and allows jokes to be added via the GUI. Something extra eg improved appearance / Joke categories

GCSE level 8-9 (A**)- As above but with something extra

Own program - Currency Converter


This should be a window which takes a value from an Entry widget and displays a converted amount in a label. Extra buttons could be added and the appearance improved. Getting the rate from the Internet is a more difficult improvement.