สมมติว่าเราต้องการสร้างแอปพลิเคชันที่เราต้องการเพิ่มคำอธิบายบนวิดเจ็ต tkinter เพื่อให้แสดงข้อความคำแนะนำเครื่องมือขณะวางเมาส์บนวิดเจ็ตปุ่ม สามารถทำได้โดยการเพิ่มคำแนะนำเครื่องมือหรือป๊อปอัป
คำแนะนำเครื่องมือมีประโยชน์ในแอปพลิเคชันที่จำเป็นต้องมีการโต้ตอบกับผู้ใช้ เราสามารถกำหนดคำแนะนำเครื่องมือโดยการสร้างอินสแตนซ์ของ Balloon(win) . หลังจากนั้น เราสามารถผูกปุ่มด้วยข้อความคำแนะนำเครื่องมือที่ใช้กับวิดเจ็ตได้
ตัวอย่าง
#Import the tkinter library
from tkinter import *
from tkinter.tix import *
#Create an instance of tkinter frame
win = Tk()
#Set the geometry
win.geometry("400x200")
#Create a tooltip
tip= Balloon(win)
#Create a Button widget
my_button=Button(win, text= "Python", font=('Helvetica bold', 20))
my_button.pack(pady=20)
#Bind the tooltip with button
tip.bind_widget(my_button,balloonmsg="Python is an interpreted, high-level
and general-purpose programming language")
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างพร้อมปุ่ม ตอนนี้ ให้วางเมาส์เหนือปุ่ม “Python” และจะแสดงข้อความคำแนะนำเครื่องมือ
