-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_editor.py
More file actions
73 lines (49 loc) · 1.58 KB
/
text_editor.py
File metadata and controls
73 lines (49 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import keyboard
import string
import time
import threading
# This creates a tuple of 'abcdef...XYZ...0123...'
allowed_chars = tuple(string.ascii_letters + string.digits + string.punctuation + " ")
note1 = ""
note2 = ""
def display_text(txt):
global final_note,note1,note2
os.system('cls')
note1 += txt
print(note1 + "|" + note2)
def blink():
while True:
os.system('cls')
print(note1 + "|" + note2)
time.sleep(0.5)
os.system('cls')
print(note1 + " " + note2)
time.sleep(0.5)
# 1. Create the thread
# timer_thread = threading.Thread(target=blink, daemon=False)
# # 2. Start the thread
# timer_thread.start()
while True:
if len(note1 + "|" + note2)/10 == len(note1 + "|" + note2)//10 :
note2 += "/n"
while True:
event = keyboard.read_event()
if event.event_type == keyboard.KEY_DOWN:
if event.name in allowed_chars:
display_text(event.name)
elif event.name == "space":
display_text(" ")
elif event.name == "backspace":
note1 = note1[:-1]
display_text("")
elif event.name == "left":
if note1 != "":
note2 = note1[-1] + note2
note1 = note1[:-1]
display_text("")
elif event.name == "right":
if note2 != "":
note1 += note2[0]
note2 = note2[1:]
display_text("")