Welcome 歡迎光臨! 愛上網路-原本退步是向前 !

Tkinter Keyboard Events

 記錄一下,資料不好找

# Python program to stop, copy, and backspace spcae

# in a text widget in Tkinter

 

# Import the library tkinter

from tkinter import *

 

# Create a GUI widget

app=Tk()

 

# Set the geometry of the app

app.geometry("700x350")

app.title( "Key  檢測程式")        

 

# Create and display text field widget

text=Text(app, font="Calibri, 14",bg='#9BCD9B',borderwidth = 5,relief = 'ridge')

text.pack(fill= X, expand= True)

 

# 禁用 Ctrl + v

text.bind('', lambda _:'break')

 

# 禁用 Ctrl + C

text.bind('', lambda _:'break')

 

# 禁用 退格鍵

text.bind('', lambda _:'break')

 

# 禁用 空白

text.bind('', lambda _:'break')

 

# Make infinite loop for displaying app

# on the screen

app.mainloop()

===========================================

keysym

Key

Alt_L

The left-hand alt key

Alt_R

The right-hand alt key

BackSpace

backspace

Control_L

The left-hand control key

Control_R

The right-hand control key

Delete

Delete

End

end

Escape

esc

F1

Function key F1

F12

Function key F12

F2

Function key F2

Fi

Function key Fi

Home

home

Insert

insert

KP_0

0 on the keypad

KP_1

1 on the keypad

KP_8

8 on the keypad

KP_9

9 on the keypad

KP_Add

+ on the keypad

KP_Begin

The center key (same key as 5) on the keypad

KP_Decimal

Decimal (.) on the keypad

KP_Delete

delete on the keypad

KP_Divide

/ on the keypad

KP_Down

↓ on the keypad

KP_End

end on the keypad

KP_Enter

enter on the keypad

KP_Home

home on the keypad

KP_Insert

insert on the keypad

KP_Left

← on the keypad

KP_Multiply

× on the keypad

KP_Next

PageDown on the keypad

KP_Prior

PageUp on the keypad

KP_Right

→ on the keypad

KP_Subtract

- on the keypad

KP_Up

↑ on the keypad

Next

PageDown

Pause

pause

Print

PrintScrn

Return

Enter key

Right

Left

Down

Shift_L

The left-hand shift key

Shift_R

The right-hand shift key

Tab

The tab key

 

[ Python ] 瀏覽次數 : 34 更新日期 : 2025/12/26