如何在 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()

輸出

上面的程式碼將顯示一個帶有“將滑鼠懸停”按鈕的視窗。當用戶懸停在按鈕上時,將顯示一個工具提示文字。

更新於: 2021 年 3 月 27 日

3K+ 檢視

開啟您的 職業

透過完成課程並獲取認證

立即開始
廣告
© . All rights reserved.