เมธอด bell() ใน Tkinter จะสร้างเสียงเริ่มต้นของระบบ (default event or dialogue sound) เมธอดนี้สามารถเรียกใช้ในหน้าต่างหรือเฟรมหลักได้ เราสามารถเปลี่ยนเสียงของหน้าต่างได้ผ่านการตั้งค่าระบบ
ในตัวอย่างนี้ เราจะสร้างปุ่มที่เมื่อกดจะสร้างเสียงเริ่มต้นของระบบ
ตัวอย่าง
# Import the library
from tkinter import *
# Create an instance of tkinter frame
win = Tk()
# Define the size of the window
win.geometry("700x150")
win.resizable(0, 0)
# Define the Bell function
def click():
win.bell()
Button(win, text="Click Me", command=click).pack(pady=20)
win.mainloop()
ผลลัพธ์
การรันโค้ดข้างต้นจะสร้างปุ่ม และเมื่อคลิกจะสร้างเสียงของระบบ
