如何在 Tkinter 中显示工具提示?
在需要在悬停在一个按钮上时显示一些信息时,工具提示很有用。
为了创建和显示一个工具提示,可以使用 Tkinter 的 Balloon 属性。
示例
#Import the tkinter library
from tkinter import *
from tkinter.tix import *
#Create an instance of tkinter frame
win = Tk()
#Set the geometry
win.geometry("600x450")
#Create a tooltip
tip = Balloon(win)
#Create a Button widget
my_button=Button(win, text= "Hover Me")
my_button.pack(pady=20)
#Bind the tooltip with button
tip.bind_widget(my_button,balloonmsg="www.tutorialspoint.com")
win.mainloop()输出
上面的代码将显示一个带有“将鼠标悬停”按钮的窗口。当用户悬停在按钮上时,将显示一个工具提示文本。

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP