Tkinter自定义创建按钮 [英] Tkinter custom create buttons

查看:333
本文介绍了Tkinter自定义创建按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以从
这样的图像或图标中窃取自定义按钮,例如



tkinter有普通按钮,我不想添加图像按钮,
i要创建新按钮或样式,

解决方案

有可能!



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



例如:

 从tkinter导入* 

根= Tk()

button = Button(root,text = Click me!)
img = PhotoImage(file = C:/image/example.gif的路径)#确保添加 /不是 \
button.config(image = img)
button.pack()#显示按钮

root.mainloop()

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


can tkinter custom buttons from a image or icon like this

tkinter have normal buttons i dont want add a image buttons i want create a new button or styles

解决方案

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.

这篇关于Tkinter自定义创建按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆