Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีซ่อนหรือปิดใช้งานตัวชี้เมาส์ใน Tkinter

ใน Tkinter สามารถควบคุมคอมโพเนนต์ของหน้าต่าง เช่น เมาส์เคอร์เซอร์ ไอคอนควบคุม 툴บาร์ ได้ผ่านฟังก์ชันในตัว

เพื่อซ่อนหรือปิดใช้งานเมาส์พอยน์เตอร์สำหรับแอปพลิเคชัน Tkinter เฉพาะ ให้ใช้เมธอด config(cursor="none") บนหน้าต่างหลัก (root/master window)

ตัวอย่างโค้ด

# Import tkinter library
from tkinter import *
from tkinter import ttk

# Create an instance of Tkinter frame or window
win = Tk()

# Set the geometry of tkinter frame
win.geometry("750x250")

def callback(event):
    win.destroy()

# Create a Label and a Button widget
label = ttk.Label(win, text="Press Enter to Close the Window", font=('Century 17 bold'))
label.pack(ipadx=10)

win.bind('', callback)

# Disable the Mouse Pointer
win.config(cursor="none")

win.mainloop()

ผลลัพธ์

การรันโค้ดจะซ่อนเมาส์พอยน์เตอร์ในหน้าต่าง

วิธีซ่อนหรือปิดใช้งานตัวชี้เมาส์ใน Tkinter

กดปุ่ม Enter เพื่อปิดหน้าต่าง