久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在python中添加背景圖像

Adding a background image in python(在python中添加背景圖像)
本文介紹了在python中添加背景圖像的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在嘗試將背景圖像添加到 Python 中的畫布.到目前為止,代碼如下所示:

I'm trying to add a background image to a canvas in Python. So far the code looks like this:

from Tkinter import *
from PIL import ImageTk,Image

... other stuffs

root=Tk()
canvasWidth=600
canvasHeight=400
self.canvas=Canvas(root,width=canvasWidth,height=canvasHeight)
backgroundImage=root.PhotoImage("D:DocumentsBackground.png")
backgroundLabel=root.Label(parent,image=backgroundImage)
backgroundLabel.place(x=0,y=0,relWidth=1,relHeight=1)
self.canvas.pack()
root.mainloop()

它返回一個(gè) AttributeError: PhotoImage

It's returning an AttributeError: PhotoImage

推薦答案

PhotoImage 不是 Tk() 實(shí)例 (root) 的屬性.這是一個(gè)來(lái)自 Tkinter 的類.

PhotoImage is not an attribute of the Tk() instances (root). It is a class from Tkinter.

所以,你必須使用:

backgroundImage = PhotoImage("D:DocumentsBackground.gif")

注意 Label 是一個(gè)來(lái)自 Tkinter 的類...

Beware also Label is a class from Tkinter...

不幸的是,Tkinter.PhotoImage 僅適用于 gif 文件(和 PPM).如果您需要讀取 png 文件,您可以使用 PILImageTk 模塊中的 PhotoImage(是的,同名)類.

Unfortunately, Tkinter.PhotoImage only works with gif files (and PPM). If you need to read png files you can use the PhotoImage (yes, same name) class in the ImageTk module from PIL.

這樣,這會(huì)將您的 png 圖像放入畫布中:

So that, this will put your png image in the canvas:

from Tkinter import *
from PIL import ImageTk

canvas = Canvas(width = 200, height = 200, bg = 'blue')
canvas.pack(expand = YES, fill = BOTH)

image = ImageTk.PhotoImage(file = "C:/Python27/programas/zimages/gato.png")
canvas.create_image(10, 10, image = image, anchor = NW)

mainloop()

這篇關(guān)于在python中添加背景圖像的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How should I verify a log message when testing Python code under nose?(在鼻子下測(cè)試 Python 代碼時(shí),我應(yīng)該如何驗(yàn)證日志消息?)
Patch __call__ of a function(修補(bǔ)函數(shù)的 __call__)
How to call self in a mock method of an object in Python?(如何在 Python 中對(duì)象的模擬方法中調(diào)用 self?)
Mocking only a single method on an object(僅模擬對(duì)象上的單個(gè)方法)
Mocking a subprocess call in Python(在 Python 中模擬子進(jìn)程調(diào)用)
Checking call order across multiple mocks(檢查多個(gè)模擬的調(diào)用順序)
主站蜘蛛池模板: 91在线亚洲 | 91午夜精品 | 黑人精品一区二区 | 18精品爽国产白嫩精品 | 日本伊人久久 | www.男人的天堂 | 久久青青 | 亚洲一区二区三区视频 | 久久精品视频国产 | 欧美成人午夜 | 欧美在线免费观看视频 | 干干干操操操 | 日本一本草久p | 久热在线视频 | 在线黄色av| 夜夜操狠狠操 | 丰满少妇高潮无套内谢 | 亚洲第一色网 | 欧美成人毛片 | 色婷婷免费视频 | 午夜精品久久久久久久 | 久久精品国产亚洲 | 男人添女荫道口图片 | 中文在线字幕免费观 | h视频在线播放 | 一区二区免费在线观看 | 青娱乐99| 黄色高清视频 | 在线亚洲精品 | 黄色在线观看免费 | 欧美激情国产精品 | 久久国产精品一区二区 | 亚洲伦理视频 | 日韩精品三区 | 黄色av免费 | 四色永久访问 | 一区二区三区四区视频 | 欧美精品一二区 | 黄网站免费在线观看 | 欧美一区二区三区免费 | 国产精品天堂 |