Python中文
首页
教程
问答
标签
搜索
登录
注册
如何使用curses stdscr.getch()在MacOS上的Jupyter笔记本中捕获按键?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我在MacOS上使用带Python3.7的Jupyter笔记本</p> <p>我已经收集了很多数据,现在我想一次一个地将其绘制出来,并使用for循环遍历这些图形。但是,我想暂停查看每个图形,然后按任意键继续下一个图形</p> <p>我尝试输入(“按ENTER键继续…”),但它会在每个图形后创建一个新行,并使整个Jupyter单元格输出在每次按ENTER键时向上滚动,因为它会为每个输入创建一个新行</p> <p>所以我尝试使用curses库stdscr.getch()来捕获键盘输入,但是它没有检测到任何键盘按键</p> <pre><code>import curses %matplotlib notebook fig,ax = plt.subplots(figsize=(10, 8)) ch = 1 for col in df.columns: if int(col) % 2 == 0: # even columns are time xs = df[col] else: # odd columns are voltage if ch == 2: ys = df[col] ax.plot(xs, ys, 'b') ax.set_xlabel('X') ; ax.set_ylabel('Y') ax.set_xlim(-30,260) ; ax.set_ylim(-10000,10000) fig.canvas.draw() #input('Press ENTER to continue...') stdscr = curses.initscr() stdscr.keypad(True) while True: key = stdscr.getch() if key != -1: print(key) if key == 27: # This is the escape key code curses.endwin() break ax.cla() ch = 1 else: ch = 2 </code></pre> <p>然而,在while-True循环中,key始终为-1。无论我按什么键,键总是-1,这意味着它根本检测不到任何键盘按键。我错过了什么?如何使用stdscr.getch()检测MacOS上Jupyter笔记本中的按键</p> <p>谢谢大家!</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>据我所知,你无法在Jupyter笔记本中捕获键盘输入。Jupyter笔记本在没有键盘的服务器上运行</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
无法使用Django/mongoengine连接到MongoDB(身份验证失败)
3 回答
无法使用Django\u mssql\u后端迁移到外部hos
1 回答
无法使用Django&Python3.4连接到MySql
5 回答
无法使用Django+nginx上载媒体文件
5 回答
无法使用Django1.6导入名称模式
4 回答
无法使用Django1.7和mongodb登录管理站点
8 回答
无法使用Djangoadmin创建项目,进程使用了错误的路径,因为我事先安装了错误的Python
7 回答
无法使用Djangockedi验证CBV中的字段
10 回答
无法使用Djangocketditor上载图像(错误400)
5 回答
无法使用Djangocron进行函数调用
6 回答
无法使用Djangofiler djang上载文件
1 回答
无法使用Djangokronos
10 回答
无法使用Djangomssql provid
3 回答
无法使用Djangomssql连接到带有Django 1.11的MS SQL Server 2016
7 回答
无法使用Djangomssq迁移Django数据库
9 回答
无法使用Djangonox创建用户
2 回答
无法使用Djangopyodb从Django查询SQL Server
4 回答
无法使用Djangopython3ldap连接到ldap
8 回答
无法使用Djangoredis连接到redis
2 回答
无法使用Django中的FK创建新表
10 回答