这段代码的问题在于,我知道实际的.png文件没有损坏,我已经在其他项目中多次测试了,我不知道为什么我的photo1
图像没有出现在我的Toplevel
窗口内。在我的顶级窗口小部件中出现这种情况的原因以及如何修复它?
from tkinter import *
from tkinter import ttk
root = Tk()
#placing of the window
w = 600
h = 250
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
root.geometry('%dx%d+%d+%d' % (w,h,x , y))
#Window title
root.title(string= "Longwood Panther Math Game Main Menu")
#The window configuration
root.resizable(width = False , height = False)
#level variable
def language_Arts(a):
root.withdraw()
language_window = Toplevel()
language_window.iconbitmap('panther.ico')
#title
language_window.title(string = 'Language Arts Main Menu')
#placing of the window
w = 500
h = 250
ws = language_window.winfo_screenwidth()
hs = language_window.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
language_window.geometry('%dx%d+%d+%d' % (w,h,x , y))
#Greetings
Greetings =Message(language_window , text = 'Welcome to The Language Arts Section, this is Where you Can Brush up on Your Grammar , and improve gramatical errors. With Multiple levels based on your skill level(grade classification)' , font= 'times 10 bold')
Greetings.grid(row = 2 , column = 0 , sticky = 'we')
#elementary
elementary = ttk.Button(language_window , text = 'Elementary')
elementary.grid(row = 2 , column = 1 , sticky = 'we')
#middle school button
middleschool = ttk.Button(language_window ,text = 'Middle School')
middleschool.grid(row = 2 , column = 2 , sticky = 'we')
#highschool button
highschool = ttk.Button(language_window , text = 'High School')
highschool.grid(row = 2 , column = 3, sticky = 'we')
# photos
photo1 = PhotoImage(file = 'grammar-cartoon.png')
photo2 = PhotoImage(file ='Matt1-240x3005.png')
#image labels
image1 = Label(language_window , image = photo1)
image1.grid(row = 3 , column = 0 , sticky = 'we')
LA_Button = ttk.Button(root , text= 'Language Arts')
LA_Button.grid(row = 4 , column = 4, sticky = 'we')
LA_Button.bind('<Button-1>' , language_Arts)
root.mainloop()