Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
I am not able is load images in new window, the main window is functioning fine and loading/displaying images but the window which is called on button click is not loading/displaying images. The GUI library that i have used is Tkinter



Python
__author__ = 'USER'
from tkinter import *
from tkinter import ttk
from  PIL import Image , ImageTk
import base64
import urllib


class Welcome():

    def __init__(self, master=None):
        self.master = master
        self.frame = Frame(self.master, width=450, height=650, bg="white")
        self.frame.pack(expand=False)
        self.master.title("Welcome To Desserts & Drinks")

        self.logo = PhotoImage(file="DrinkLogo.png")
        self.label_1 = Label(self.frame, image=self.logo)
        self.label_1.grid(row=1, column=0, sticky=E)

        self.label_2 = Label(self.frame, text="Desserts & Drinks", font="Magneto 26   bold italic", bg="white", fg="Crimson", padx=0,pady=5)
        self.label_2.grid(row=1, column=1, sticky=W)

        self.dessert = PhotoImage(file="DessertLogo.png")
        self.label_3 = Label(self.frame, image=self.dessert)
        self.label_3.grid(row=100, column=0, sticky=W)

        self.drink = PhotoImage(file="Drinks.png")
        self.label_3 = Label(self.frame, image=self.drink)
        self.label_3.grid(row=110, column=0, sticky=W)

        self.start = PhotoImage(file="S.png")
        self.label_4 = Label(self.frame, image=self.start)
        self.label_4.grid(row=120, column=0, sticky=W)

        self.button_1 = Button(self.frame, text="D  e  s  s  e  r  t  s", width=30, height=4, bg="Crimson", fg="White", font="Algerian 15", activebackground="LightPink",activeforeground="Black",command=self.gotoDesserts)
        self.button_2 = Button(self.frame, text="D  r  i  n  k  s", width=30, height=4, bg="white", fg="Crimson", font="Algerian 15",activebackground="LightPink",activeforeground="White")
        self.button_3 = Button(self.frame, text="S  t  a  r  t  e  r  s", width=30, height=4, bg="Crimson", fg="White",  font="Algerian 15",activebackground="LightPink",activeforeground="Black")
        self.button_4 = Button(self.frame, text="E  x  i  t", width=30, height=4, bg="white", fg="Crimson",  font="Algerian 15", activebackground="LightPink",activeforeground="white",command=self.finish)

        self.exit = PhotoImage(file="cancelButton.png")
        self.label_5 = Label(self.frame, image=self.exit)
        self.label_5.grid(row=130, column=0, sticky=W)

        self.button_1.grid(row=100, column=1,sticky=E)
        self.button_2.grid(row=110, column=1,sticky=E)
        self.button_3.grid(row=120, column=1,sticky=E)
        self.button_4.grid(row=130, column=1,sticky=E)

    def gotoDesserts(self):
        root2=Toplevel(self.master)
        myGUI=Desserts(root2)

    def finish(self):
        self.master.destroy()

class Desserts():

 from tkinter import ttk
 from PIL import Image, ImageTk, ImageFile, ImageFileIO, ImageShow

 def __init__(self, master):
        self.master = master


        self.frame = Frame(self.master, width=480, height=650, bg="white")
        self.frame.grid()
        self.master.title("Welcome To Desserts")

        self.logo = PhotoImage(file="DrinkLogo.png")
        self.label_1 = Label(self.frame, image=self.logo).place(x=55,y=10)

        self.photo = PhotoImage(file="dessert1.png")
        self.label_5 = Label(self.frame, image=self.photo,bg="White")
        self.checkbutton_1 = self.ttk.Checkbutton(self.frame,image=self.photo).place(x=0, y=120)



        self.label_2 = Label(self.frame, text="Desserts & Drinks", font="Magneto 26 bold italic", bg="white", fg="Crimson", padx=0,pady=5).place(x=110,y=5)

        self.label_4 = Label(self.frame, text=" D e s s e r t s     M e n u \t\t\t", width=50, height=2, bg="Crimson", fg="White", font="Algerian 15", padx=0, pady=0).place(x=0, y=60)

        self.photo = PhotoImage(file="dessert1.png")
        self.label_5 = Label(self.frame, image=self.photo, bg="White").place(x=0, y=120)
        self.checkbutton_1 = self.ttk.Checkbutton(self.frame, image=self.photo).place(x=0, y=120)

        self.label_6 = Label(self.frame, text="Chocolate Dessert",font="Harrington 16 bold underline",width=18,height=1,bg="White",fg="Crimson").place(x=130, y=115)
        self.label_7 = Label(self.frame, text="Hard Corded Chocolate Cover, \nDeliciously Stuffed With Double Vanilla and Sprinked With \nGrated Dark Chocolate",bg="Crimson",fg="Azure",font="Forte 10").place(x=130,y=145)


        self.photo_1 = PhotoImage(file="dessert2.png")
        self.label_8 = Label(self.frame, image=self.photo,bg="White").place(x=0, y=210)
        self.checkbutton_2 = self.ttk.Checkbutton(self.frame,image=self.photo_1).place(x=0, y=210)

        self.label_9 = Label(self.frame,text="Chocolate Vanilla Grated Smudge",font="Harrington 16 bold underline",width=28,height=1,bg="White",fg="Crimson").place(x=120, y=210)
        self.label_10 = Label(self.frame,text="Soft Vanilla Smudge, \nDeliciously Batted With Fine Cream For A Delicious Smudge \n Chocolate Vanilla",bg="Crimson",fg="Azure",font="Forte 10").place(x=130,y=240)



        self.photo_3 = PhotoImage(file="Drinks_1.png")
        self.label_11 = Label(self.frame, image=self.photo_3).place(x=0,y=290)

        self.button_1 = Button(self.frame, text="D r i n k s", width=35, height=4, bg="Crimson", fg="White", font="Algerian 15", activebackground="LightPink",activeforeground="Black").place(x=108,y=292)

        self.photo_4 = PhotoImage(file="S.png")
        self.label_12 = Label(self.frame, image=self.photo_4).place(x=0,y=400)

        self.button_2 = Button(self.frame, text="S t a r t e r s", width=35, height=4, bg="White", fg="Crimson", font="Algerian 15", activebackground="LightPink",activeforeground="Black").place(x=108,y=395)

        self.photo_5 = PhotoImage(file="O.png")
        self.label_13 = Label(self.frame, image=self.photo_5).place(x=0, y=500)


        self.button_2 = Button(self.frame, text="Place Order", width=10, height=6, bg="Crimson", fg="White", font="Algerian 15", activebackground="LightPink",activeforeground="Black").place(x=120,y=500)

        self.exit = PhotoImage(file="cancel_1.png")
        self.label_14 = Label(self.frame, image=self.exit).place(x=250,y=500)
        self.button_2 = Button(self.frame, text="Exit", width=9, height=6, bg="Azure", fg="Crimson", font="Algerian 15", activebackground="LightPink",activeforeground="Black").place(x=370,y=500)












def main():
    root = Tk()
    myGUIWelcome=Welcome(root)
    root.mainloop()

if __name__ == '__main__':
    main()
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900