Python终端菜单?终端着色?终端进度显示? [英] Python Terminal Menu? Terminal Coloring? Terminal progress display?

查看:37
本文介绍了Python终端菜单?终端着色?终端进度显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个广泛使用 Python(2.* 风格)的项目,我想知道是否有终端菜单库或类似的东西?我希望通过使用箭头键可突出显示的选项、某些颜色等来简化一些选项,为我的脚本注入一些风味和生命力.我依稀记得有一种方法可以制作 bash shell 终端菜单,但我不在确定我将如何将用户输入从 bash 传递到 python 脚本,也许有一个 bash 终端菜单使用 sysarggs 推送脚本调用?如果可能的话,我想要一些 Python 方面的东西.有什么建议吗?

I have a project that uses Python (2.* flavors) extensively and I am wondering if there is a terminal menu library or something to that effect? I am looking to breathe some flavor and life into my script by simplifying some of the options using arrow key highlightable options, some color, etc etc. I vaguely recall there being a way to make a bash shell terminal menu but I'm not at all sure how I would pass user input from bash to the python script, perhaps have a bash terminal menu push the script call with sysarggs? I'd like something on the python side if possible. Any suggestions?

也只是一个随机问题,因为我们讨论的是终端美学的主题,所以这里很适合,处理计数器的最佳方法是什么?我的脚本查找图像文件,然后当它找到一个时,它会通过子进程调用清除终端以清除,然后再次打印找到的总图像 IE 10 图像,找到一个,清除,打印找到 11 个图像",有时我的脚本有效真的很快,我觉得这会损害性能.想法?

Also just a random question, kind of fits in here since we're on the topic of terminal aesthetics, what's the best way to handle a counter? My script looks for image files, then when it finds one it clears the terminal with a subprocess call to clear and then prints the total images found again IE 10 images, find one, clear, print "11 images found", sometimes my script works REAL fast and I feel this detriments performance. Thoughts?

非常感谢大家,我喜欢堆栈溢出;)

Thanks so much everyone, I love stack overflow ;)

编辑 - 感谢所有快速回复!我有很多选择可以考虑.我给了每个人一个赞,因为你们所有的回答都很有帮助.当我回到家时,我会查看所有图书馆,并尝试根据最佳答案选择你们中的一个作为答案,但希望我能选择你们所有人,因为你们所有的答案都是相关的!非常感谢人们.我下班回家后会回来报告,并有机会编写代码;)

Edit - Thanks for all the quick responses! I have alot of options to mull over. I gave everyone an upvote because all of your responses are helpful. I will check out all the libraries when I get home and try to pick one of you for an answer depending on what hashes out the best, wish I could pick you all though because all of your answers are relevant! Much appreciated folks. I'll report back in once I get home from work and get a chance to get some coding in ;)

编辑 2 - 对计数器/进度显示的澄清,当我的脚本在很短的时间内找到数千张图像时,寻找一种方法来防止它损害性能,这是真正切碎的 python...

Edit 2 - A clarification on the counter/progress display, looking for a way to keep this from detrimenting performance when my script finds thousands of images in a very short ammount of time, this is real chopped up python...

for each item in list:
    if item ends with .jpg
        cnt=cnt+1
        do stuff with image file
        subprocess.call('clear')
        print str(cnt)+" total images processed."

再次感谢!

推荐答案

有一个名为 Urwid 的库提供菜单等等.我从来没有将它用于严肃的目的,但根据我的初步经验,它工作得很好.但它仅适用于 Un*x 系统.(项目页面说它可以在 Cygwin 下运行,但我从未尝试过.)

There's a library called Urwid that offers menus and some more. I never used it for serious purposes, but the it work pretty fine with my preliminary experiences on it. It works on Un*x systems only though. (The project page says it works under Cygwin, but I never tried.)

这篇关于Python终端菜单?终端着色?终端进度显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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