I am doing a school project, to make a game using tkinter. I am trying to display and image by using an image link stored in a text file, however it will only display the image if there is an error at the end of the def subroutine that stops the program. I am having trouble understanding why it will show the image if there is an error stoping the program but will display everything else but the image if there is no error(by error i mean some random letters in the code)
Am I missing something?
Note: the game involves picking which country a flag belongs to.
import tkinter as tk
from PIL import ImageTk,Image
import random
import time
main_window = tk.Tk()
main_window.title("Fun With Flags")
...... #removed the unnecessary part
def play():
#opens the question text file
question_file = open('Flags.txt')
lines = question_file.readlines()
image_link = lines[1]
#removes the \n from the end of the variable
size = len(image_link)
flag_link = image_link[:size - 1]
print(flag_link)
#Finds the image dimensions
flag = Image.open(flag_link)
width = flag. size[0]
height = flag. size[1]
print(width)
print(height)
#Resizes the image
new_height = 200
new_width = int(new_height * width / height)
flag = flag.resize((new_width, new_height), Image.ANTIALIAS)
#Displays the flag
flag = ImageTk.PhotoImage(flag)
c.create_image(450, 300, image = flag, anchor = "s")
homepage()