當前位置:編程學習大全網 - 網站源碼 - python Tkinter.TK與PIL.ImageTK的問題

python Tkinter.TK與PIL.ImageTK的問題

img?=?ImageTk.PhotoImage(im)

看上面壹句,我們需要關註的是PhotoImage這個方法,所以看下他的源碼

self.__photo?=?tkinter.PhotoImage(**kw)

發現了上面這壹句

是的它調用了tkinter下面的PhotoImage方法

class?PhotoImage(Image):

"""Widget?which?can?display?colored?images?in?GIF,?PPM/PGM?format."""

def?__init__(self,?name=None,?cnf={},?master=None,?**kw):

"""Create?an?image?with?NAME.

Valid?resource?names:?data,?format,?file,?gamma,?height,?palette,

width."""

Image.__init__(self,?'photo',?name,?cnf,?master,?**kw)

上面是tkinter.PhotoImage

可以發現PhotoImage這個類,繼承自Image

class?Image:

"""Base?class?for?images."""

_last_id?=?0

def?__init__(self,?imgtype,?name=None,?cnf={},?master=None,?**kw):

self.name?=?None

if?not?master:

master?=?_default_root

if?not?master:

raise?RuntimeError('Too?early?to?create?image')

self.tk?=?getattr(master,?'tk',?master)

明顯,tkinter他是有檢查master 這個東西的。

也就是下面這壹句有沒有寫

root?=?tk.Tk()

所以,當妳把順序換了以後,他就報錯了。

  • 上一篇:word文檔怎麽下載免費版
  • 下一篇:為什麽周立功的開發板ucos只能創建10個任務?
  • copyright 2024編程學習大全網