Python curses.getmouse ()

#!/usr/bin/env python # -*- coding: utf-8 -*- import curses screen = curses.initscr() curses.noecho() curses.curs_set(0) screen.keypad(1) curses.mousemask(1) screen.addstr("This is a Sample Curses Script\n\n") while True: event = screen.getch() if event == ord("q"): break if event == curses.KEY_MOUSE: screen.addstr(curses.getmouse()) curses.endwin() 

if event == curses.KEY_MOUSE: screen.addstr(curses.getmouse()) I think I should get the text that the mouse is clicked on or not? All I get is TypeError: str . Why is this? What am I missing? I could not find good textbooks on this topic. Thanks.

+4
source share
1 answer
 import curses screen = curses.initscr() #curses.noecho() curses.curs_set(0) screen.keypad(1) curses.mousemask(1) screen.addstr("This is a Sample Curses Script\n\n") while True: event = screen.getch() if event == ord("q"): break if event == curses.KEY_MOUSE: _, mx, my, _, _ = curses.getmouse() y, x = screen.getyx() screen.addstr(y, x, screen.instr(my, mx, 5)) curses.endwin() 

You should read the docs more carefully, everything is there :-)

+8
source

Source: https://habr.com/ru/post/1396105/


All Articles