Python curses.getmouse()

匿名 (未验证) 提交于 2019-12-03 08:52:47

问题:

#!/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 where mouse is clicked or not? All I get is TypeError: str. Why is that? What am I missing? I couldn't find any good tutorials on this topic. Thanks.

回答1:

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, it's all in there :-)



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!