Question

Here is my current program:

from tkinter import *
from tkinter import messagebox
from collections import deque


class App():

    def __init__(self, *images):
        self.root = Tk()
        self.root.title("Disease")
        self.root.bind("<Button-1>", self.click_event)

        self.image_dict = {image: PhotoImage(file=image) for image in images}
        self.image_queue = deque(images)

        start_image = self.image_dict[self.image_queue[0]]
        self.label = Label(self.root, image=start_image)
        self.label.image = start_image
        self.label.pack()

    def change_image(self):
        self.image_queue.rotate(-1)
        next_image = self.image_queue[0]
        self.label.configure(image=self.image_dict[next_image])
        self.label.image = self.image_dict[next_image]

    def click_event(self, event):
        print ("clicked at", event.x, event.y )
        if (8 < event.x < 241) and (150 < event.y < 232):
            messagebox.showinfo("Description", "- Also known as the 'Stone Man Syndrome', it's a rare disease that affects the connective tissue.\n\n- Whenever tissue is damaged, instead of the body healing and repairing the wounds, it grows bone in its place.\n\n- Sometimes the body will even begin spontaneously growing excess bone throughout the body for no reason, leading to extremely limited movement.")

        if (255 < event.x < 494) and (150 < event.y < 232):
            messagebox.showinfo("Causes", "- FOP is caused by mutation of certain genes and chromosomes, more specifically the ACVR1 protein, something that is used to help control the functions of cells.\n\n- There is no known cure. The only thing sufferers can do is have surgery to remove the excess bone, but that ends up growing back.")

        if (8 < event.x < 241) and (245 < event.y < 317):
            messagebox.showinfo("People Affected", "- At the moment there are only around 700 people around the world who have been confirmed for having FOP. Nobody knows how many people have been affected with it in the past.")

        if (255 < event.x < 494) and (245 < event.y < 317):
            messagebox.showinfo("Pictures", "")

        if (8 < event.x < 494) and (327 < event.y < 388):
            messagebox.showinfo("Sources", "http://en.wikipedia.org/wiki/Fibrodysplasia_ossificans_progressiva\n\nhttp://ghr.nlm.nih.gov/condition/fibrodysplasia-ossificans-progressiva\n\nhttp://www.ifopa.org/fop-fact-sheet.html")

if __name__ == "__main__":
    app = App('1.gif')
    app.root.mainloop()

Which produces this

enter image description here

And everything is good, everything runs fine, it's just that I need to find a way to have pictures appear when someone clicks on the "Pictures" box, which i'm not sure how to do. I know that I need something other than the messagebox, but I don't know what. Any help?

Was it helpful?

Solution

Here is a simple Toplevel widget that you can use to display an image in a new window.

from Tkinter import *

top = Toplevel()
diagrams = PhotoImage(file='your image')
logolbl= Label(top, image = diagrams)
logolbl.grid()

mainloop()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top