PyD*_*Der 14
这是可能的!
如果您查看按钮文档,则可以使用图像在按钮上显示.
例如:
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()
Run Code Online (Sandbox Code Playgroud)
这是将图像添加到按钮小部件的简化示例,您可以使用按钮小部件制作更多更酷的内容.
对于一个Tkinter的项目,我创建了一个TkinterCustomButton上的顶级构建tkinter.Frame。它在tkinter.Canvas. 您可以像普通 一样使用它tkinter.Button,但它是高度可定制的。您可以更改角半径、边框宽度和所有颜色:
因此,如果您希望 tkinter 按钮看起来像问题中的示例一样定制且更现代,则并不总是需要使用图像。
虽然这并不能真正回答问题,但也许这个例子对某人有帮助。
你可以在TkinterCustomButton这里找到类和示例程序:
https : //github.com/TomSchimansky/GuitarTuner/tree/master/documentation
最简单的例子是:
import tkinter
from tkinter_custom_button import TkinterCustomButton
app = tkinter.Tk()
app.geometry("300x200")
app.title("TkinterCustomButton")
def button_function():
print("Button pressed")
button_1 = TkinterCustomButton(text="My Button", corner_radius=10, command=button_function)
button_1.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
app.mainloop()
Run Code Online (Sandbox Code Playgroud)
这使:
在 Windows 上,我体验到 tkinter 画布的渲染质量非常糟糕,所以圆形,尤其是细边框看起来不太好......
| 归档时间: |
|
| 查看次数: |
16715 次 |
| 最近记录: |