在 Python Tkinter 按鈕上新增影像
Tkinter 是 Python 程式設計的 GUI 庫,它具有一個用於向 GUI 按鈕新增影像的功能。這有助於使用者記住 GUI 中的符號,而不是 GUI 中的文字。在下面的 Tkinter 程式中,我們展示瞭如何向 GUI 按鈕新增影像。使用了 imageKT 模組中的 photoimage 方法。我們提到了影像檔案的本地路徑。
示例
from tkinter import * from PIL import ImageTk ,Image base = Tk() base.title('Start Button') img=ImageTk.PhotoImage(Image.open ("D:\button.jpg")) lab=Label(image=img) lab.pack() button=Button(base,text='exit',command=base.quit) button.pack() base.mainloop()
輸出
執行上面的程式碼會給我們以下結果 -
廣告