在按钮中创建图像
问题描述:
如何在按钮中创建图像.我希望它是画笔的图片,而不是说画"的文字.
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()