Changing the shape of tkinter widgets

孤者浪人 提交于 2020-11-29 10:24:49

问题


So I have a simple button:

f1button3=Button(text="Database", command = lambda: DatabaseWidgets()).place(x=1,y=30)

The buton is always a rectangle, but I want it to have curved edges, or possibly even change the shape. Is this at all possible?


回答1:


I hit the same problem. My solution was to use an image, then bind that to a click. Here is the code I used:

from Tkinter import *
from PIL import ImageTk, Image

app = Tk()

def do(event):
    print("Button Clicked!")
    #...

img = ImageTk.PhotoImage(Image.open("Button.gif"))
button = Label(app, image = img)
button.pack()

button.bind('<Button-1>', do)

app.mainloop()

The <Button-1> binds the image to a right click. The "Button.gif" is the picture I used.

Here is the output picture:



来源:https://stackoverflow.com/questions/36328547/changing-the-shape-of-tkinter-widgets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!