Skip to content

Commit 5a1dc87

Browse files
committed
control-keyrelease-a
1 parent d783fab commit 5a1dc87

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

tkinter/__links__/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
![#1](screenshots/image-1.png?raw=true)
3+
4+
# Key names
5+
6+
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/key-names.html
7+
8+
http://www.tcl.tk/man/tcl8.4/TkCmd/keysyms.htm
9+
10+
# Events
11+
12+
- [54.6. Writing your handler: The Event class](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/event-handlers.html) (NMT)
13+
- [54.3. Event types](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/event-types.html)
14+
15+
- [How to bind Ctrl+/ in python tkinter?](http://stackoverflow.com/a/16082411/1832058) (SO)
16+
17+
---
18+
19+
- NMT = [New Mexico Tech](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html)
20+
- Effbot - [An Introduction to Tkinter](http://effbot.org/tkinterbook/tkinter-index.htm)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
StackOverflowa: [CTRL + a select all in entry widget tkinter python](http://stackoverflow.com/questions/41477428/ctrl-a-select-all-in-entry-widget-tkinter-python/41478726#41478726)
3+
4+
Selecting text in `Entry` using `Ctrl+A` as in other programs - it highlights text so it can be coped into cliboard.
5+
6+
# example-1.py
7+
8+
Because after releasing keys `<Control-a>` selection is removed
9+
so I use `after()` to execute selection after 50ms.
10+
It selects all text (but it moves cursor to the beginning)
11+
and moves cursor to the end.
12+
13+
# example-2.py
14+
15+
Before I couldn't find correct combination with `Release`
16+
but it has to be `<Control-KeyRelease-a>`
17+
and now it doesn't need `after()`
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
3+
'''
4+
Because after releasing keys `<Control-a>` selection is removed
5+
so I use `after()` to execute selection after 50ms.
6+
It selects all text (but it moves cursor to the beginning)
7+
and moves cursor to the end.
8+
'''
9+
10+
import tkinter as tk
11+
12+
def callback(event):
13+
print('e.get():', e.get())
14+
# or more universal
15+
print('event.widget.get():', event.widget.get())
16+
# select text after 50ms
17+
root.after(50, select_all, event.widget)
18+
19+
def select_all(widget):
20+
# select text
21+
widget.select_range(0, 'end')
22+
# move cursor to the end
23+
widget.icursor('end')
24+
25+
root = tk.Tk()
26+
27+
e = tk.Entry(root)
28+
e.pack()
29+
e.bind('<Control-a>', callback)
30+
31+
root.mainloop()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
'''
4+
Before I couldn't find correct combination with `Release`
5+
but it has to be `<Control-KeyRelease-a>`
6+
and now it doesn't need `after()`
7+
'''
8+
9+
import tkinter as tk
10+
11+
def callback(event):
12+
13+
print('e.get():', e.get())
14+
# or more universal
15+
print('event.widget.get():', event.widget.get())
16+
17+
# select text
18+
event.widget.select_range(0, 'end')
19+
# move cursor to the end
20+
event.widget.icursor('end')
21+
22+
root = tk.Tk()
23+
24+
e = tk.Entry(root)
25+
e.pack()
26+
e.bind('<Control-KeyRelease-a>', callback)
27+
28+
root.mainloop()

0 commit comments

Comments
 (0)