Bewegen Sie den Cursor über mehrere Linien in PythonPython

Python-Programme
Guest
 Bewegen Sie den Cursor über mehrere Linien in Python

Post by Guest »

Also versuche ich, einen einfachen Texteditor zu machen, um Python zu lernen. Ich versuche zu lernen, indem ich etwas mache. Gestern hatte ich nach nicht blockierenden Tastatur -Listening
hier
gefragt und ich habe dieses Problem gelöst
Derzeit sieht mein Code so aus: < /p>
'''
imports: keyboard for listening to CTRL
readline for navigating cursor in a line
'''
import readline
# import keyboard
from pynput import keyboard
lines = ""

def write(line_count , no_of_lines):
'''
function:write
parameters:line_count,no_of_lines
returns:none
'''
global lines
print(line_count,no_of_lines)
print(f"Default line count {no_of_lines}")
print(f"Buffer Length {len(lines)}")
print("press CTRL key to set line to 1")
print("start typing")
print("--------------------------------------")
# def on_ctrl_event(event):
# nonlocal line_count
# if event.name == 'ctrl':
# line_count = 1
# keyboard.on_press(on_ctrl_event)
def on_release(key):
nonlocal line_count
if key == keyboard.Key.ctrl:
line_count = 1
# with keyboard.Listener(on_release=on_press) as listener:listener.join()
# non vlocking
listener = keyboard.Listener(on_release=on_release)
listener.start()
while line_count > 0:
lines += input() + "\n"
line_count -= 1
if line_count == 0:
print("last line")
try:
inc_line = int(input(" or 0: "))
except ValueError:
inc_line = 0
if inc_line > 0:
no_of_lines += inc_line
line_count += inc_line
def main():
'''
function:main
returns:none
main entry point
'''
global lines
while True:
event = input("'n' to write ,'s' to save , 'v' to view buffer , 'q' to exit: ")
if event == 's' and (len(lines)>1):
filename = input("filename>")
path = input("path>")
try:
with open(f"{path}{filename}", "w",encoding='utf-8') as file:
file.write(lines)
print("Saved the content\nBuffer is cleared")
except (OSError, FileExistsError) as error:
print(error)
elif event == 'v' and len(lines) > 1:
print(lines)
elif event == 'q':
break
elif event == "n":
lines = ""
write(5,5)
else:
print(f"Current Buffer length: {len(lines)} must be > than 1")

if __name__=="__main__":
main()

< /code>
Ich möchte meinen Cursor dazu bringen, mehrere Zeilen zu verschieben. Derzeit bewegt es
in der aktuellen Zeile bitte. Bitte helfen Sie mir < /p>
Ich möchte machen Mein Cursor, um mehrere Zeilen zu verschieben, werden derzeit nur
in der aktuellen Zeile bewegt. Bitte helfen Sie mir. Ich habe herausgefunden, dass ich Readline importieren kann, aber wenn ich den Pfeil auf den Pfeil drehe>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post