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

วิธีกำหนดค่า Double-Click เริ่มต้นของเมาส์ใน Text Widget Tkinter


Widget Text ใน Tkinter ใช้เพิ่มฟังก์ชันคล้าย text editor รองรับการป้อนข้อมูลหลายบรรทัด ตั้งค่าคุณสมบัติ text widget ด้วย configure()

Text widget มี tagging สำหรับเลือกข้อความ ขยายฟังก์ชันนี้ ผูก Double-Click เพื่อเลือกคำทีละคำ

ตัวอย่าง

ตัวอย่างปิดการใช้งาน double-click เลือกข้อความ

# Import the required libraries 
from tkinter import * 
# Create an instance of tkinter frame or window 
win = Tk() 
# Set the size of the tkinter window 
win.geometry("700x350") 
# Define a function to get the length of the current text 
def select_all(): 
    text.tag_add("start", "1.0", "end") 
    return "break" 
# Create a text widget 
text = Text(win, width=50, height=10, font=('Calibri 14')) 
text.pack() 
text.insert(INSERT, "Select a word and then double-click") 
# Bind the buttons with the event 
text.bind('', select_all) 
win.mainloop()

ผลลัพธ์

รันโค้ด จะแสดง text widget พร้อมข้อความกำหนดไว้ เลือกคำแล้ว double-click เพื่อเลือกคำนั้น

วิธีกำหนดค่า Double-Click เริ่มต้นของเมาส์ใน Text Widget Tkinter