Pythoncurses.getmouse()

发布于 2025-01-05 10:24:12 字数 576 浏览 0 评论 0原文

#!/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()) 我想我应该获取单击鼠标或未单击鼠标的文本?我得到的只是 TypeError: str。这是为什么?我缺少什么?我找不到关于这个主题的任何好的教程。谢谢。

#!/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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当爱已成负担 2025-01-12 10:24:12
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()

您应该更仔细地阅读 docs ,一切都在那里:-)

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 :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文