Python Tkinter 自定义创建按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39054156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:49:20  来源:igfitidea点击:

Tkinter custom create buttons

pythonbuttontkinterpython-3.5

提问by Golge Adam

can tkinter custom buttons from a image or icon like this enter image description here

可以从这样的图像或图标 tkinter 自定义按钮 在此处输入图片说明

enter image description here

在此处输入图片说明

tkinter have normal buttons i dont want add a image buttons i want create a new button or stylesenter image description here

tkinter 有普通按钮我不想添加图像按钮我想创建一个新按钮或样式在此处输入图片说明

回答by PyDer

It's possible!

这是可能的!

If you check out the button documentation, you can use an image to display on the button.

如果您查看按钮文档,您可以使用图像显示在按钮上。

For example:

例如:

from tkinter import *

root = Tk()

button = Button(root, text="Click me!")
img = PhotoImage(file="C:/path to image/example.gif") # make sure to add "/" not "\"
button.config(image=img)
button.pack() # Displaying the button

root.mainloop()

This is a simplified example for adding an image to a button widget, you can make many more cool things with the button widget.

这是将图像添加到按钮小部件的简化示例,您可以使用按钮小部件制作更多很酷的东西。