from PIL import ImageTk
import PIL.Image
from tkinter import*
from tkinter import messagebox
class login_interface(Frame):
def __init__(self,master=None):
Frame.__init__(self,master)
self.master=master
self.security()
def security(self):
self.master.title("LOGIN")
self.pack(fill=BOTH, expand=1)
lbl = Label(self, text="PASSWORD").grid(column=0, row=0)
self.pwrd = Entry(self,show="*")
self.pwrd.focus_set()
self.pwrd.grid(column=1, row=0)
login = Button(self, text="login", width=20,command=self.login)
login.grid(column=1, row=2)
def login(self):
if self.pwrd.get()=="a":
a.destroy()
b=Tk()
b.geometry("%dx%d" % (width, height))
app_b=question(b)
app_b.mainloop()
else:
messagebox.showinfo("ERROR ","retry wrong password")
class question(Frame):
def __init__(self,master=None):
Frame.__init__(self,master)
self.master=master
self.master.title("Question")
self.pack(fill=BOTH, expand=1)
test = Label(self, image=ImageTk.PhotoImage((PIL.Image.open(r"tree.jpg").resize((50,50)))))
test.pack()
lbl = Label(self, text="Who made the pythagoras theorem?").place(relx=0.5, rely=0.3, anchor='center')
self.my_guess = Entry(self)
self.my_guess.place(relx=0.5, rely=0.5, anchor='center')
my_enter = Button(self, text="Enter", command=self.check).place(relx=0.5, rely=0.7, anchor='center')
def check(self):
if self.my_guess.get() == "Pythagoras":
messagebox.showinfo("Correct","Go to Next Quiz.")
else:
messagebox.showinfo("Wrong", "Try Again.")
a=Tk()
width= a.winfo_screenwidth()
height= a.winfo_screenheight()
a.geometry("%dx%d" % (width, height))
app=login_interface(a)
app.mainloop()
I have been trying to find the problem in the code from a long time, the tree.jpg file doesn't appear in the screen at all, even after checking that the photo is in the same folder as the program.I would be really grateful if someone could help me find the problem in the code.
i have tried changing the photos and cross checking photo locations, but still the photo doesn't show up