- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to show the status of CAPS Lock Key in tkinter?
We can use the <Lock-KeyPress> and <Lock-KeyRelease> bindings to check if the CAPS Lock Key is ON or off. In the following example, we will create two user-defined functions "caps_lock_on()" and "caps_lock_off()" which will capture the event of Lock-KeyPress and Lock-KeyRelease and print the status on the screen.
# Import required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win = Tk() # Define the geometry of the window win.geometry("700x250") win.title("CAPS Lock Status") def caps_lock_on(e): label_caps.config(text="CAPS Lock is ON") def caps_lock_off(e): label_caps.config(text="CAPS Lock is OFF") label_caps = Label(win, font="Helvetica 15 bold") label_caps.pack(pady=20) win.bind("<Lock-KeyPress>", caps_lock_on) win.bind("<Lock-KeyRelease>", caps_lock_off) win.mainloop()
When the user presses the CAPS Lock, it will show its current status, whether it is ON or OFF.
- Check if Caps Lock and Num Lock is on or off through Console in C#
- How to show webcam in TkInter Window?
- How to show and hide widgets in Tkinter?
- Lock & Key problem using Hash-map
- How to show multiple Canvases at the same time in Tkinter?
- How to bind the Enter key to a tkinter window?
- How to hide and show canvas items on Tkinter?
- How to bind the spacebar key to a certain method in Tkinter?
- How to bind the Escape key to close a window in Tkinter?
- How to lock the rotation of Ellipse using FabricJS?
- How to bind a key to a button in Tkinter?
- How do I bind the enter key to a function in Tkinter?
- How to obtain Status of the Current Thread in C#?
- How to lock the Android device programmatically?