Я создаю проект mysql / tkinter и пытаюсь использовать изображение в качестве bg для одного из windows. но вместо того, чтобы появляться в новом окне, вместо этого он открывается в главном окне. Я хочу, чтобы изображение открывалось в новом окне, в котором я сейчас работаю. menu () само по себе работает так, как я предполагал, но со всей программой это не так. есть идеи, как я могу это исправить?
def menu():
root = tk.Tk()
root.title("DBMS Menu Page")
bgimage= ImageTk.PhotoImage(Image.open('960x0.jpg'))
imglabel= Label(image=bgimage)
imglabel.img=bgimage
imglabel.pack()
lblmenu = tk.Label(root,text ="MENU", font=('Times New Roman',28,'bold'))
lblmenu.place(x = 220, y = 60)
btninsert = tk.Button(root, text ="Insert",
fg ='blue',font=("Times New Roman Bold", 10))
btninsert.place(x = 100, y = 135, width = 60)
btnupdate = tk.Button(root, text ="Update",
fg ='blue',font=("Times New Roman Bold", 10))
btnupdate.place(x = 170, y = 135, width = 60)
btndelete = tk.Button(root, text ="Delete",
fg ='blue',font=("Times New Roman Bold", 10))
btndelete.place(x = 240, y = 135, width = 60)
btndisplay = tk.Button(root, text ="Display",
fg ='blue',font=("Times New Roman Bold", 10))
btndisplay.place(x = 310, y = 135, width = 60)
def clearlogin():
txtUser.delete(0,END)
txtpass.delete(0,END)
def submitact():
user = txtUser.get()
passw = txtpass.get()
print(f"The ID-pw entered by you is {user} {passw}")
logintodb(user, passw)
def logintodb(user, passw):
if passw:
db = mys.connect(host ="localhost",
user = user,
password = passw,
db ="1234")
cursor = db.cursor()
else:
db = mys.connect(host ="localhost",
user = root,
database ="1234")
cursor = db.cursor()
# A Table in the database
savequery = "show tables"
try:
cursor.execute(savequery)
myresult = cursor.fetchall()
print("Query Excecuted succesfully")
messagebox.showinfo("Login ", "Login Successful")
except:
db.rollback()
print("Error occured")
menu()
root = tk.Tk()
root.geometry("250x150")
root.title("DBMS Login Page")
lbluser = tk.Label(root, text ="Username -",fg="red",font=("Times New Roman Bold", 13) )
lbluser.place(x = 10, y = 20)
txtUser = tk.Entry(root, width = 35,fg="green",font=("Times New Roman Bold", 10))
txtUser.place(x = 100, y = 20, width = 100)
lblpass = tk.Label(root, text ="Password -",fg="red",font=("Times New Roman Bold", 13))
lblpass.place(x = 10, y = 50)
txtpass = tk.Entry(root,show="*", width = 35,fg="green",font=("Times New Roman Bold", 10))
txtpass.place(x = 100, y = 50, width = 100)
submitbtn = tk.Button(root, text ="Login",
fg ='blue', font=("Times New Roman Bold", 15),command = submitact)
submitbtn.place(x = 30, y = 100, width = 55)
clearbtn = tk.Button(root, text ="Clear",
fg ='blue', font=("Times New Roman Bold", 15),command = clearlogin)
clearbtn.place(x = 130, y = 100, width = 55)
root.mainloop()