У меня есть основной код, в котором используются команды вывода и удаления значка, которые работают. Когда я применяю их к различным функциям (которые не влияют на основной код), они, похоже, не работают.
Я получаю следующую ошибку:
homeButton = Button (content, width = 50, height = 50, command = lambda: [homePage.deiconify (), resourcePage.destroy ()]) AttributeError: объект 'function' не имеет атрибута 'deiconify'
Я сделал небольшой фрагмент соответствующего кода из моего кода, чтобы вы могли протестировать его, если хотите
Просто нажмите кнопку отправки на первой странице, нажмите кнопку ресурсов на следующей странице и кнопку домой в левом верхнем углу страница будет та, которая не работает как должно быть
from tkinter import *
def resourcePage():
global homeIcon
global file
resource = Toplevel()
resource.title("Resource Page")
resource.resizable(0, 0)
header = LabelFrame(resource, bg="white")
content = LabelFrame(resource, bg="white")
header.columnconfigure(0, weight=1) # Forces column to expand to fill all available space
homeButton = Button(content, width=50, height=50, command=lambda:[homePage.deiconify(), resourcePage.destroy()])
#HERE IS THE ERROR ^^
try:
homeIcon = PhotoImage(file="yes.png")
homeButton.config(image=homeIcon)
homeButton.image = homeIcon
except TclError:
print("Home")
homeButton.grid(row=1, column=0, sticky="w", padx=2, pady=2)
# each section of code below is for their respective labels on the page
papersLabel = Label(content, text="Exam Papers", bg="#12a8e3", fg="white", font=("Ariel", 26, "bold"),
activebackground="#12a8e3", anchor="w", padx=15)
papersLabel.grid(row=2, column=0, padx=15, pady=(15, 5), ipadx=429, ipady=10)
papersPhysics = Label(content, text="Physics:", bg="white", font=("Ariel", 22), anchor="w")
papersPhysics.grid(row=3, column=0, sticky="w", padx=20)
papersHyperlinks = Label(content, text="• Hyperlinks here", bg="white", font=("Ariel", 18), anchor="w")
papersHyperlinks.grid(row=4, column=0, sticky="w", padx=24)
papersCS = Label(content, text="Computer Science:", bg="white", font=("Ariel", 22), anchor="w")
papersCS.grid(row=5, column=0, sticky="w", padx=20)
papersHyperlinks = Label(content, text="• Hyperlinks here", bg="white", font=("Ariel", 18), anchor="w")
papersHyperlinks.grid(row=6, column=0, sticky="w", padx=24)
questionsLabel = Label(content, text="Practice Exam Questions:", bg="#12a8e3", fg="white",
font=("Ariel", 26, "bold"), activebackground="#12a8e3", anchor="w", padx=15)
questionsLabel.grid(row=7, column=0, padx=15, pady=(25, 5), ipadx=328, ipady=10)
questionsPhysics = Label(content, text="Physics:", bg="white", font=("Ariel", 22), anchor="w")
questionsPhysics.grid(row=8, column=0, sticky="w", padx=20)
questionsHyperlinks = Label(content, text="• Hyperlinks here", bg="white", font=("Ariel", 18), anchor="w")
questionsHyperlinks.grid(row=9, column=0, sticky="w", padx=24)
questionsCS = Label(content, text="Computer Science:", bg="white", font=("Ariel", 22), anchor="w")
questionsCS.grid(row=10, column=0, sticky="w", padx=20)
questionsHyperlinks = Label(content, text="• Hyperlinks here", bg="white", font=("Ariel", 18), anchor="w")
questionsHyperlinks.grid(row=11, column=0, sticky="w", padx=24)
videosLabel = Label(content, text="Helpful Videos:", bg="#12a8e3", fg="white", font=("Ariel", 26, "bold"),
activebackground="#12a8e3", anchor="w", padx=15)
videosLabel.grid(row=12, column=0, padx=15, pady=(25, 5), ipadx=415, ipady=10)
videosPhysics = Label(content, text="Physics:", bg="white", font=("Ariel", 22), anchor="w")
videosPhysics.grid(row=13, column=0, sticky="w", padx=20)
videosHyperlinks = Label(content, text="• Hyperlinks here", bg="white", font=("Ariel", 18), anchor="w")
videosHyperlinks.grid(row=14, column=0, sticky="w", padx=24)
videosCS = Label(content, text="Computer Science:", bg="white", font=("Ariel", 22), anchor="w")
videosCS.grid(row=15, column=0, sticky="w", padx=20)
videosHyperlinks = Label(content, text="• Hyperlinks here", bg="white", font=("Ariel", 18), anchor="w")
videosHyperlinks.grid(row=16, column=0, sticky="w", padx=24,
pady=(0, 25)) # y padding here to keep some space from the bottom of the page
header.grid(row=0, sticky='NSEW')
content.grid(row=1, sticky='NSEW')
def homePage():
homePage = Toplevel()
homePage.title("Home Page")
homePage.resizable(0, 0)
header = LabelFrame(homePage, bg="#12a8e3")
content = LabelFrame(homePage, bg="white")
header.columnconfigure(0, weight=1) # Forces column to expand to fill all available space
title = Label(header, text="School Subjects Quiz", bg="#12a8e3", fg="white", font=("Ariel", 35, "bold"), padx=10,
pady=10)
title.grid(row=0, column=0, columnspan=3)
# I will add thumbnails to the buttons in later development phases
questionsButton = Button(content, text="Questions", padx=380, pady=100, bg="#12a8e3", fg="white",
font=("Ariel", 45, "bold"), activebackground="#12a8e3", command=lambda:[subjectSelection(), homePage.withdraw()])
questionsButton.grid(row=1, column=0, columnspan=3, padx=15, pady=40)
accountButton = Button(content, text="Account", padx=100, pady=135, bg="#12a8e3", fg="white",
font=("Ariel", 45, "bold"), activebackground="#12a8e3", command=lambda:[accountPage(), homePage.withdraw()])
accountButton.grid(row=2, column=0, padx=30, pady=35)
resourceButton = Button(content, text="Revision" + "\n" + "Resources", padx=100, pady=100, bg="#12a8e3", fg="white",
font=("Ariel", 45, "bold"), activebackground="#12a8e3", command=lambda:[resourcePage(), homePage.withdraw()])
resourceButton.grid(row=2, column=1, padx=30, pady=35)
header.grid(row=0, sticky='NSEW')
content.grid(row=1, sticky='NSEW')
#Creating the log in page
root = Tk()
root.title("Log-in page")
root.geometry('1000x850') #creates dimensions of page
root.resizable(0,0) #will disable max/min tab of window
#seperating the page into sections
header = LabelFrame(root, bg="#12a8e3")
content = LabelFrame(root, bg="white")
root.columnconfigure(0, weight=1) # 100%
root.rowconfigure(0, weight=2) # 2%
root.rowconfigure(1, weight=98) # 98%
#creating the title of the page to be displayed in the header
title = Label(header, text="School Subjects Quiz", bg="#12a8e3", fg="white", font=("Ariel",65, "bold"), padx=10, pady=10)
title.pack(expand=TRUE)
#username input box
usernameLabel = Label(content, width = 60, borderwidth=5, font=("Ariel", 22), text="Enter Username", bg="white", anchor="w", padx=100)
usernameLabel.pack(ipady = 8, pady=(55,0))
usernameBox = Entry(content, width = 60, borderwidth=5, font=("HelvLight", 18))
usernameBox.pack(ipady = 10)
#password input box
passwordLabel = Label(content, width = 60, borderwidth=5, font=("Ariel", 22), text="Enter Password", bg="white", anchor="w", padx=100)
passwordLabel.pack(ipady = 8, pady=(55,0))
passwordLabel = Entry(content, width = 60, borderwidth=5, font=("HelvLight", 18))
passwordLabel.pack(ipady = 10)
#submit buttons for inputs
submitButton = Button(content, width = 20, borderwidth=5, font=("Ariel", 22), text="Submit", bg="#b5b5b5", fg="black", activebackground="#b5b5b5", command=lambda:[homePage(), root.withdraw()])
submitButton.pack(ipady = 5, pady=(15,0))
#button to click on to make an account
registerButton = Button(content, width = 40, borderwidth=5, font=("Ariel", 24), text="New? Click here to register", bg="#12a8e3", fg="white", activebackground="#12a8e3", command=lambda:[register(), root.withdraw()])
#withdraw hides the window and register calls upon the register function
registerButton.pack(ipady = 20, pady=(100,0))
header.grid(row=0, sticky='news')
content.grid(row=1, sticky='news')
root.mainloop()