Не работает метод clear()
Вот есть такой код:
import time
import os
clear = lambda: os.system('cls')
root = tk.Tk()
root.title("Sys.tem")
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
window_width = 350
window_height = 200
x = (screen_width // 2) - (window_width // 2)
y = (screen_height // 2) - (window_height // 2)
root.geometry(f"{window_width}x{window_height}+{x}+{y}")
text = ""
def func1(event):
global text
text += event.char
if event.keysym == "Return":
print(text)
text = ""
elif event.keysym == "End":
print(f"{text}", end='')
time.sleep(2)
print('\r', end='')
elif event.keysym == "Prior":
clear()
root.bind("<KeyPress>", func1)
root.mainloop()
И при нажатии клавиши Prior (PgUp) консоль должна очищаться методом clear(). Но почему то этого не происходит. Подскажите, в чем проблема или чем можно заменить данную функцию?
Ответы (1 шт):
Автор решения: Vladyslav
→ Ссылка
Вот код для очистки консоли в разных операционных системах
def clear_console():
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
И запускать в Вашем коде …
elif event.keysym == "Prior":
clear_console()