Skip to content

Workshop 3 - Sem 1 2024

In this workshop, we'll go over the steps to making a GUI (Graphical User Interface) using Tkinter in Python.

Cheat Sheet for tkinter Application

Import tkinter Module

from tkinter import *

Create Main Window

main_window = Tk()

Customize Main Window

main_window.title('WEFCS')
main_window.geometry("800x400")

Create Widgets

  1. Title Frame: Create a label for the application title and for the logo
title_frame = LabelFrame(main_window)
app_title = Label(title_frame, text='Wayne Enterprises Fact Checking Services')
# Your file name of your photo should be the same here
# Tkinter only supports png and gif formats
photo = PhotoImage(file="logo.png")
logo_label = Label(title_frame, image=photo)
  1. Updatable Screen Label: Create a label to display updatable text and a frame for the sources button.
updatable_screen = Label(main_window, text='this is the updatable text.')

 buttonSource_frame = LabelFrame(main_window)
  1. Source Buttons: Create buttons for selecting sources A, B, and C.
# Code for Button A
# First create a function for the command
def updateText_A():
 # You need to update the label corresponding to this and you can do it by using config
 updatable_screen.config(text='You choose Source A.')
# After that you can call the command into your button
button_A = Button(buttonSource_frame, text='Source A', command=updateText_A)
# Code for Button B
# Code for Button C
  1. Rating System: Create labels for instructions and current rating, buttons for positive and negative reviews, and a button to save the review.
rating_label = Label(ratingSystem_frame, text='Please leave this a rating:')
# Write code for showRating
# Same as before you need to write a command function to put into your buttons
# Hint: You can use a global variable and update the showRating Label
positive_button = Button(ratingSystem_frame, text='Positive', command=positiveReview)
# Code for Negative review button
# Save review button
  1. View Options: Create buttons for preview and full view options.
preview_button = Button(viewOption_frame, text='preview')
fullView_button = Button(viewOption_frame, text='fullView')

Grid Placement

You can format your gui by using a grid placement. This is done using columns and rows starting at 0.

title_frame.grid(column=0,row=0)
app_title.grid(column=0, row=0)
logo_label.grid(column=0, row=1)
updatable_screen.grid(column=1, row=0)
buttonSource_frame.grid(column=0, row=1)
ratingSystem_frame.grid(column=1, row=1)
viewOption_frame.grid(column=0, row=2)

Start Event Loop

main_window.mainloop()