【发布时间】:2018-09-05 01:30:27
【问题描述】:
我正在尝试运行一些同时使用 tkinter 和 Pillow 的 Python 代码。当我在我的 IDE (Pycharm) 中运行代码时,程序会打开并且没有问题。但是,当我尝试将代码作为 Python 文件单独运行时,我会快速闪现命令提示符,该提示符会立即关闭。我正在运行 Python 3.7.0(最新版本),这意味着我还有最新版本的 tkinter 以及 Pillow 5.2.0。如何让我的代码在其 UI 中作为独立的 python 文件运行?
from tkinter import *
from PIL import Image, ImageTk
root = Tk()
mapFrame=Frame(root)
mapFrame.place(relx=0, rely=0, relheight=0.85, relwidth=1)
subMapFrame = Frame(mapFrame)
subMapFrame.place(relx=0.05,rely=0.1,relwidth=0.9, relheight=0.9)
image = Image.open("field.png")
img_copy= image.copy()
background_image = ImageTk.PhotoImage(image)
background = Label(subMapFrame, image=background_image)
background.pack(fill=BOTH, expand=YES)
root.mainloop()
【问题讨论】:
标签: python tkinter python-imaging-library tk