python png格式的图片做button


一、png格式的图片
import tkinter
from PIL import Image, ImageTk

root = tkinter.Tk()
img = Image.open("timg1_new.png")
img_ = ImageTk.PhotoImage(img)
button = tkinter.Button(root, image=img_, width=100, height=100)
button.place(x=10, y=10)

root.mainloop()
'''
注意事项:
1、图片格式为.png
2、图片长宽大小要与button长宽一致
3、img_ 定义为全局变量。若不是全局变量,可能图片不会显示。
'''


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM