如何在Tkinter中显示图像? [英] How to show an image in Tkinter?

查看:3230
本文介绍了如何在Tkinter中显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我当前的程序:

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()

哪个生产这个

一切都很好,一切运行良好,只是我需要找到一种方法,当有人单击图片"框时显示图片,我不确定该怎么做.我知道我需要除消息框之外的其他东西,但我不知道什么.有帮助吗?

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?

推荐答案

这是一个简单的顶级小部件,可用于在新窗口中显示图像.

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()

这篇关于如何在Tkinter中显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆