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
提问by Golge Adam
回答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.
这是将图像添加到按钮小部件的简化示例,您可以使用按钮小部件制作更多很酷的东西。