I'm trying to add some images on my GUI program, but there is something wrong with it
I used the following code:
import tkinter as tk
import tkinter.simpledialog as tkSimpleDialog
import tkinter.messagebox as tkMessageBox
from tkinter import ttk
import time
from PIL import ImageTk, Image
LargeFont = ("Verdana", 12)
class PageContainer(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.iconbitmap(self,default="ico_image.ico")
container = tk.Frame(self)
tk.Tk.geometry(self,'800x600')
container.pack(side='top', fill='both', expand = True )
container.grid_rowconfigure(0, weight = 1)
container.grid_columnconfigure(0, weight = 1)
self.frame = {}
for F in (StartPage, Local_Window,Remote_Window,Manual_Window,Automatic_Window):
frame = F(container, self)
self.frame[F] = frame
frame.grid(row = 0, column = 0, sticky = "nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frame[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Maintenance System", font = LargeFont)
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text = "Local",
command = lambda: controller.show_frame(Local_Window), width = 20, height = 3)
button2 = tk.Button(self, text = " Remote ",
command = lambda: controller.show_frame(Remote_Window), width = 20, height = 3)
button3 = tk.Button(self, text=" Exit ",
command=lambda: StartPage.quit(self), width=20, height=3)
button1.place(x = 325, y = 200)
button2.place(x = 325, y = 300)
button3.place(x = 100, y = 500)
acwa_power_img = Image.open("ACWA_Power_logo.png")
acwa_power_img = acwa_power_img.resize((150, 80), Image.ANTIALIAS)
acwa_power_img = ImageTk.PhotoImage(acwa_power_img)
acwa_power_label = tk.Label(self, image=acwa_power_img)
acwa_power_label.place(x = 0, y = 0)
hiwpt_img = Image.open("hiwpt2.jpg")
hiwpt_img = hiwpt_img.resize((150, 80), Image.ANTIALIAS)
hiwpt_img = ImageTk.PhotoImage(hiwpt_img)
hipwt_label = tk.Label(self, image=hiwpt_img)
hipwt_label.place(x = 646, y =0 )
StartPage.configure(self,background='grey')
app = PageContainer()
app.mainloop()
This is what I got when I run my program:
the images are fine, and also the dir is ok, what is the problem?
I searched a lot and I didn't find any solution.