在按钮中创建图像 [英] Create image in button
本文介绍了在按钮中创建图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在按钮中创建图像.我希望它是画笔的图片,而不是说画"的文字.
How do I create an image in button. Instead of having text saying "Draw" I want it to be a picture of a brush.
代码:
self.draw_button = Button(self.root, text='Draw', command=self.use_draw)
self.draw_button.grid(row=0, column=2)
推荐答案
使用 tkinter 的 PhotoImage
创建图像,然后将其设置在 Button 中.
Create an image with tkinter's PhotoImage
then set it inside Button.
from tkinter import *
root = Tk()
img = PhotoImage(file='paint_brush.png')
draw_button = Button(root, image=img)
draw_button.grid(row=0, column=0)
root.mainloop()
这篇关于在按钮中创建图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文