简体   繁体   English

在Python 3.5 Tkinter中将图像用作按钮

[英]Using an image as a button in Python 3.5 Tkinter

使用tkinter,如何使按钮变成图片而不是文本?

Some searching revealed Image on a button . 一些搜索显示按钮上的图像 It uses the PhotoImage function. 它使用PhotoImage功能。 To explain some code included in it: 要解释其中包含的一些代码:

from Tkinter import *                         # Import tkinter
root=Tk()                                     # Create an instance using Tk()
b=Button(root,justify = LEFT)                 # Create a button
photo=PhotoImage(file="mine32.gif")           # Give photo an image
b.config(image=photo,width="10",height="10")  # Configure the earlier instance to use the photo
b.pack(side=LEFT)                             # Pack up the button
root.mainloop()                               # Create everything

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM