0

so I have been trying to display an image viewer app in a new tab from my first one. Wanted that after I click a button a new tab with pictures will appear. Is it possible to do using Tkinter? If so here is the part of the code and I would love any advice:

root = tk.Tk()
root.title('chat bot for discord')
def newV():
    set = tk.Tk()
    image1 = ImageTk.PhotoImage(Image.open("-----------------------.jpg"))
    image2 = ImageTk.PhotoImage(Image.open("-----------------------.jpg"))
    image3 = ImageTk.PhotoImage(Image.open("-----------------------.jpg"))
    image4 = ImageTk.PhotoImage(Image.open("-----------------------.jpg"))
    image5 = ImageTk.PhotoImage(Image.open("-----------------------.jpg"))
    image6 = ImageTk.PhotoImage(Image.open("-----------------------.jpg"))
    image7 = ImageTk.PhotoImage(Image.open("-----------------------.jpg"))
    image8 = ImageTk.PhotoImage(Image.open("-----------------------.jpg"))
    image9 = ImageTk.PhotoImage(Image.open("-----------------------.jpg"))
    image10 = ImageTk.PhotoImage(Image.open("-----------------------.jpg"))
    image_list = [image1, image2, image3, image4, image5, image6, image7, image8, image9, image10]
    image_label = ttk.Label(image=image1)
    image_label.grid(column=1, row=1, columnspan=3)
    def next(slides_num):
        image_label = ttk.Label(image=image_list[slides_num - 1])
        nextButton = ttk.Button(set, text=">>", command=lambda: next(slides_num + 1))
        if slides_num == 10:
            nextButton = ttk.Button(set, text="done", state=DISABLED)
        image_label.grid(column=1, row=1, columnspan=3)
        functionButton.grid(column=1, row=5)
        nextButton.grid(column=2, row=5)

    functionButton = ttk.Button(set, text="press here")
    nextButton = ttk.Button(set, text=">>", command=lambda: next(2))
    functionButton.grid(column=1, row=5)
    nextButton.grid(column=2, row=5)
    set.mainloop()

newVariablesButton = ttk.Button(root, text="set computer cordinates", command=newV)
newVariablesButton.grid(column=2, row=5)
root.mainloop()
  • for now I did that it will work only after I close my first tab. – Adam Sin Feb 03 '22 at 17:16
  • See [Why are multiple instances of Tk discouraged](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged). Also, if you want a label inside a particular window, you should make it a child or descendant of that window. – Bryan Oakley Feb 03 '22 at 17:19
  • `set.mainloop()` won't return until the window has been destroyed. – Bryan Oakley Feb 03 '22 at 17:43

0 Answers0