如何在python中获取没有按下回车键就按下的键? [英] How to get in python the key pressed without press enter?

查看:767
本文介绍了如何在python中获取没有按下回车键就按下的键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了此处一种解决方案,但我没有不想等到按键被按下.我想按下最后一个键.

I saw here a solution, but i don't want wait until the key is pressed. I want to get the last key pressed.

推荐答案

如@ S.Lott所述,相关问题可能会对您有所帮助:

The related question may help you, as @S.Lott mentioned: Detect in python which keys are pressed

我正在写信,尽管是要给你一些建议:不要担心. 您尝试制作哪种程序? 在终端上运行的程序通常没有使实时"击键变得有趣的接口.如今不行.对于在终端中运行的程序,您应该使用optparse或其他模块来担心有用的命令行用户界面.

I am writting in, though to give yu advice: don't worry about that. What kind of program are you trying to produce? Programas running on a terminal usually don't have an interface in which getting "live" keystrokes is interesting. Not nowadays. For programs running in the terminal, you should worry about a usefull command line User Interfase, using the optparse or other modules.

对于交互式程序,您应该使用GUI库并为用户创建一个体面的UI,而不是重新发明轮子.用户单击一个图标,在屏幕上打开一个窗口,上面有几个按钮,并且随着屏幕上所有窗口的弹出,在文件"菜单下打包了六个左右的菜单选项-或-打开了一个黑色终端带有80年代外观的文本界面以及一些带有蓝色突出显示的菜单选项等.您可以将Tkinter用于简单的窗口应用程序,因为它已预装在Python + Windows中,因此您的用户不必担心安装附加库.

For interative programs, you should use a GUI library and create a decent UI for your users, instead of reinventing the wheel.Which wouldb eb etter for what you ar trying to do? Theuser click on an icon,a window opens on the screen, witha couple of buttons on it, and half a dozen or so menu options packed under a "File" menu as all the otehr windws on the screen - or - a black terminal opens up, with an 80's looking text interface with some blue-highlighted menu options and so on?. You can use Tkinter for simple windowed applications, as it comes pre-installed with Python + Windows, so that yoru users don't have to worry about installign aditional libraries.

将其明确表述为:任何需要用户界面的程序都应具有GUI库或具有WEB界面.尝试创建在终端上运行的UI浪费了您和您的用户的时间-我们不再是1989年了.

Rephrasing it just to be clear: Any program that requires a user interface should either se a GUI library, or have a WEB interface. It is a waste of your time, and that of your users, to try and create a UI operating over the terminal - we are not in 1989 any more.

如果您绝对需要文本界面,则应查看ncurses库.比尝试重新发明轮子更好.

If you absolutely need a text interface, you should look at the ncurses library then. Better than trying to reinvent the wheel.

这篇关于如何在python中获取没有按下回车键就按下的键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆