How to click a button to open new window with image in the new window? I already check other post but nothing solve my problem, so, I'm making this question for the first time. So this is my code
from tkinter import *
from tkinter.font import BOLD
from turtle import onclick, onscreenclick
from PIL import ImageTk,Image
mainwindow=Tk()
mainframe=Frame(mainwindow,bg="white")
mainframe.pack(fill="both",expand=True)
#Label
label=Label(mainframe,text="Lucky Draw",bg="blue",fg="white",padx=5,pady=5)
label.config(font=("Times New roman",20,BOLD))
label.pack(fill="x")
horizontal_frame=Frame(mainframe,bg="white")
#lottery
def ubt1():
b1["text"]="Blender"
b1["bg"]="red"
newwin=Tk()
newwin.geometry("800x800")
c=Canvas(newwin,bg="blender",height=800,width=800)
bgimage=PhotoImage(file="D://LuckyDraw//blender.png")
background_label=Label(newwin,image=bgimage)
background_label.place(x=0,y=0,relwidth=1,relheight=1)
c.pack()
newwin.mainloop()
b1=Button(horizontal_frame,text="1",bg="green",fg="white",padx=10,pady=10,height=1,width=7,command=ubt1,font=("Poppins",10,BOLD))
b1.grid(row=0,column=0,padx=6,pady=10,sticky="nsew")
def ubt():
b2["text"]="Stove"
b2["bg"]="red"
b2=Button(horizontal_frame,text="2",bg="green",fg="white",padx=10,pady=10,height=1,width=7,command=ubt,font=("Poppins",10,BOLD))
b2.grid(row=0,column=1,padx=6,pady=10,sticky="nsew")
horizontal_frame.pack(fill="x")
mainwindow.mainloop()
I'm testing a lucky draw program.
So when start running the program user can choose 1 or 2.
1 is a big prize and 2 is a small price.
So if the user choose 2,it will just show what prize the user win but just by changing the color and text of what the user win.
But if the user choose 1,I want to open a new window with the blender picture in the new window to let the user know that he wins the big prize.
The problem here is when clicking the 1 button the new window pop up but without the image.
I try running with separate file and that show the image but when I put that code in the upper file the image doesn't show up anymore.
from tkinter import *
from tkinter import messagebox
root=Tk()
root.geometry("800x800")
c=Canvas(root,bg="white",height=200,width=200)
filename=PhotoImage(file="D://LuckyDraw//blender.png")
background_label=Label(root,image=filename)
background_label.place(x=0,y=0,relwidth=1,relheight=1)
c.pack()
root.mainloop()
I found a way to disply the image by destroying the buttons but even after the 1st user choose 1 and win the big prize by seeing the image in the new window, I also want to let the 2nd user choose 2 to know what he wins.
So how can I display the image if the user press 1 and see the prize.
After that we want to come back to the main program without losing the first progress of choosing the 1 button.
I'm really really sorry if my question is complicated because this is my first time asking question on stakoverflow and my english is not very good.