Kev*_*vin 2 python tkinter button
因此,在 Tkinter 中,按钮似乎具有浮雕属性。这默认为凸起,当按下按钮时,它会变为凹陷。我使用了relief=FLAT,但是当我点击这个按钮时它仍然是凹陷的。有没有办法让它在点击时有不同的浮雕?它会涉及更改边框颜色吗?
Button(text=day, width=2,
relief=FLAT, activebackground = self.color_clicked,
background = self.today_color)
Run Code Online (Sandbox Code Playgroud)
这看起来很平坦,但是当我点击它时,它会变成下沉的(很明显,当我松开时它会变回平面)。
您可以将鼠标单击与强制按钮浮雕以使其保持平坦的功能相关联,否则鼠标单击将使用其单击时的默认操作:使按钮下沉。
def keep_flat(event): # on click,
if event.widget is btn: # if the click came from the button
event.widget.config(relief=FLAT) # enforce an option
def callback():
print('button clicked')
root = Tk()
btn = Button(root, text='click', relief=FLAT, command=callback)
btn.pack()
root.bind('<Button-1>', keep_flat) # bind the application to left mouse click
mainloop()
Run Code Online (Sandbox Code Playgroud)
另一种选择是将按钮单击绑定到字符串“break”,这可以防止任何典型的事件处理程序启动(包括按钮的command选项):
btn.bind('<Button-1>', lambda e: 'break')
Run Code Online (Sandbox Code Playgroud)
http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
| 归档时间: |
|
| 查看次数: |
12409 次 |
| 最近记录: |