0
我想獲得一個.gif動畫工作旁邊的按鈕上的圖片。但我似乎有問題,我導入這些模塊 「導入Tkinter」和「從PIL導入圖像,ImageTk,ImageSequence」 但是,只要我「導入Tkinter」---「從Tkinter導入* 「 它說Tkinter沒有定義,我搜查了..並搜查....我不能爲我的死亡找到解決辦法。 我不得不使用「從Tkinter導入*」,因爲我不知道在哪裏可以找到「*」的子項的特徵,我還需要使用「標籤」,「bg」和「relief」 這裏是我的代碼:Tkinter和PIL錯誤
import Tkinter
from PIL import Image, ImageTk, ImageSequence
class App:
def __init__(self, parent):
self.parent = parent
self.canvas = Tkinter.Canvas(parent, width = 400, height = 500)
self.canvas.pack()
self.sequence = [ImageTk.PhotoImage(img)
for img in ImageSequence.Iterator(
Image.open(
r'C:\Users\Damian\Pictures\Gif folder\Originals\Bunnychan.gif'))]
self.image = self.canvas.create_image(200,200, image=self.sequence[0])
self.animating = True
self.animate(0)
def animate(self, counter):
self.canvas.itemconfig(self.image, image=self.sequence[counter])
if not self.animating:
return
self.parent.after(33, lambda: self.animate((counter+2) % len(self.sequence)))
root = Tkinter.Tk()
root.title('App')
app = App(root)
root.mainloop()
我有另一塊,我要使用此代碼合併:
import webbrowser
from Tkinter import *
from PIL import ImageTk,Image
Url1 = 'https://www.nedbank.co.za'
Url2 = 'https://www.facebook.com'
def openUrl1():
webbrowser.open(Url1, 2)
def openUrl2():
webbrowser.open(Url2, 2)
root = Tk()
root.title('App')
root.minsize(width = 400, height = 400)
root.maxsize(width = 400, height = 400)
image = Image.open("C:\\Users\\Damian\\Pictures\\Lores.png")
photo = ImageTk.PhotoImage(image)
label = Label(image = photo)
label.image = photo
label.place(x = 0, y = 0)
color1 = 'white'
button1 = Button(
text = color1,
bg = color1,
relief = "raised",
width = 220,
height = 85,
command = openUrl1
)
Original = Image.open("C:\\Users\\Damian\\Pictures\\NedbankLogoNew.png")
im_pm = ImageTk.PhotoImage(Original)
button1.config(image = im_pm)
button1.place(x = 0, y = 0)
root.mainloop()
你爲什麼試圖將'import Tkinter'從Tkinter import *'更改爲''?第一種是首選方式。爲了獲得您需要的物品,您可以寫一些類似'從Tkinter import Label,bg,relief'。 – martineau
我導入了「標籤」,似乎現在導入我的照片,謝謝!只需要看看bg和其他人的工作......因爲我目前無法導入BG和救濟...... – Damian
謝謝一堆!一切正常。 – Damian