0

I tried to ensure that when I click on a button, the same window appears, so I created a function (oui) and I simply copy and paste the code already present, but when I run the program and when I click on the "yes" button, it only displays an empty window. Could someone help me to solve this problem?

import tkinter as tk
import tkinter.font as tkFont
from random import*
f=1
def oui():

    app = tk.Tk()
    app.geometry(f"450x500+{randint(25,1450)}+{randint(25, 555)}")
    app.iconbitmap('icoob.ico')
    app['background']='#EBF6F4'
    app.resizable(width=True, height=True)
    longueur = 15
    largeur = 4

    AYS = tk.Label(app ,
                            text="Are you stupid ?",
                            font=("Helvetica",25))   
    Yes = tk.Button(app,
                            text="Yes",
                            width=longueur,
                            height=largeur,
                            command=oui)
    No = tk.Button(app,
                            text="No",
                            width=longueur,
                            height=largeur)
    Exit = tk.Button(app,
                            text="Exit",
                            width=longueur,
                            height=largeur,
                            command=app.destroy)

    img=tk.PhotoImage(file='azerty.png')
    tk.Label(app,image=img).place(x=100, y=150)

    Yes.place(x=35, y=350)
    No.place(x=300, y=350)
    AYS.place(x=110 ,y=80)
    Exit.pack(side=tk.BOTTOM)
    
    app.mainloop()


app = tk.Tk()   
app.geometry(f"450x500+{randint(25,1450)}+{randint(25, 555)}")
app.iconbitmap('icoob.ico')
app['background']='#EBF6F4'
app.resizable(width=False, height=False)
longueur = 15
largeur = 4

AYS = tk.Label(app ,
                            text="Are you stupid ?",
                            font=("Helvetica",25))   
Yes = tk.Button(app,
                           text="Yes",
                           width=longueur,
                           height=largeur,
                           command=oui)
No = tk.Button(app,
                           text="No",
                           width=longueur,
                           height=largeur)
Exit = tk.Button(app,
                           text="Exit",
                           width=longueur,
                           height=largeur,
                           command=app.destroy)

img=tk.PhotoImage(file='azerty.png')
tk.Label(app,image=img).place(x=100, y=150)

Yes.place(x=35, y=350)
No.place(x=300, y=350)
AYS.place(x=110 ,y=80)
Exit.pack(side=tk.BOTTOM)

app.mainloop()


(An error message is displayed when I click on the "yes" button, that's it:
   *Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\ishih\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "c:\Users\ishih\Desktop\Are you stupid\are_you_stupid.py", line 34, yes
    tk.Label(app,image=img).place(x=100, y=150)
  File "C:\Users\ishih\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 3177, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "C:\Users\ishih\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2601, in __init__
    self.tk.call(
_tkinter.TclError: image "pyimage2" doesn't exist)

0 Answers0