0

I am trying to create a 4 pics 1 word replica. When i run my code no window opens even though I have included .mainloop() at the end of the code. I have tried to create buttons for letters and an entry box gets and displays the input and enter button checks if the input is right. My code worked fine before including the image part. I have checked online for help and the code for the image seems fine. So, I dont know where the error is. It would be really nice if you can help me out.Thanks!! <3

import tkinter
from PIL import ImageTk, Image

window = tkinter.Tk()
window.title("4 Pics 1 Word")
window.geometry("546x600")

botFrame = tkinter.Frame(window)
botFrame.pack(side=tkinter.BOTTOM)

word = "APPLE"
wordLength = 5

Letters = [
    'A','I','H','O','P','U',
    'P','R','E','Z','L','Q']

row = 5
col = 0
for i in Letters:
    button_style = 'raised'
    action = lambda x = i: click_event(x)
    tkinter.Button(window, text = i, width = 7, height = 3, relief =     button_style, command = action) \
    .grid(row = row, column = col, sticky = 'nesw', )
    col += 1
    if col > 5:
        col = 0
        row += 1

tkinter.Button(window, text= "CLEAR", width = 7, height = 3, relief =  button_style, command = lambda x = "CLEAR": clear_event(x))\
                   .grid(row = 7, column = 0)

tkinter.Button(window, text= "ENTER", width = 7, height = 3, relief = button_style, command = lambda x = "ENTER": enter_event(x))\
                   .grid(row = 7, column = 2)

display = tkinter.Entry(window, width = 40, bg = "white")
display.grid(row = 0, column = 0, columnspan = 8)


img = ImageTk.PhotoImage(Image.open("Level1.gif"))
panel = tkinter.Label(botFrame, image = img)
panel.image = img
panel.pack(side = "bottom", fill = "both", expand = "yes")


def clear_event(key):
    if key == "CLEAR":
        display.delete(0,tkinter.END)

def enter_event(key):
    if key == "ENTER":
        final = display.get()
        if final == word:
            display.delete(0,tkinter.END)
            tkinter.messagebox.showinfo( "Congrats!!", "YOU WIN!!")


def click_event(key):
    display.insert(tkinter.END, key)

window.mainloop()

1 Answer 1

1

Delete this code and try: botFrame.pack(side=tkinter.BOTTOM) because it looks like you can't use geometry and pack at the same time so either you have to leave the geometry or pack

I hope this will work for you.

Sign up to request clarification or add additional context in comments.

4 Comments

I tried it properly. The window opened with every content except the image. :(
Yes, for the image part you have to search something. Best of luck.
Thanks for your help! Appreciate it. Do you know anything about it by any chance?
I didn't work on PIL library and I tried to install the PIL but I can't install it. So. have no idea about it. I am sorry @Djoker

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.