在基于 Python 文本的 GUI (TUI) 中输入 [英] Input in a Python text-based GUI (TUI)

查看:29
本文介绍了在基于 Python 文本的 GUI (TUI) 中输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在 python 2.7 中制作我自己的基于文本的 UI,但我想到了一个关于输入的想法.所以我想出了这样的事情:input = raw_input("|" + "input: ".center(78) + "|"),但粗略地说,光标在右边很远(在我输入它之前才意识到它不起作用:P).所以,问题是,我如何在屏幕中间放置一个输入,文本在同一行(两侧)并在我写下输入:"后有光标类型?如果你想知道,我正在使用这个:

I have been trying to make my own UI that is text-based in python 2.7, but I thought of an idea about input. So I figured something like this: input = raw_input("|" + "input: ".center(78) + "|"), but of coarse, the cursor is way far on the right (just realized it wouldn't work before i even typed it in :P). So, the question is, is how do I put an input in the middle of the screen with text on the same line (on both sides) and have the cursor type after I write "Input: "? And if your wondering, im using this:

if True:
    print c + "Hi! This is a text-based GUI!".center(78, h) + c
    print c + "-" * 78 + c
    print v + "OPTIONS".center(78) + v
    print c + "-" * 78 + c
    print v + "1 - Quit".center(78) + v
    for i in range(1, 7):
        print v + " " * 78 + v
    print c + "-" * 78 + c

在解释器中看起来不错:

in the interpreter and it looks decent:

+------------------------Hi! This is a text-based GUI!-------------------------+
+------------------------------------------------------------------------------+
|                                   OPTIONS                                    |
+------------------------------------------------------------------------------+
|                                   1 - Quit                                   |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
+------------------------------------------------------------------------------+

注意:我使用的是 Windows XP

Note: I use Windows XP

推荐答案

也可以试试有用的构建在 curses 之上的高级框架 urwid.有了那个东西,你可以做丰富多彩的界面.按钮编辑字段,甚至状态栏进度栏以及您需要的所有内容.要开始工作,您只需要安装 Python curses 和带有其源代码的 urwid 文件夹(您可以将整个 urwid 库与您的应用程序作为独立包一起传输!).它甚至可以在 Windows XP/7 下的 cygwin 下工作,正如我们所知,Python 没有 curses 端口.

Also try useful built atop curses high level framework urwid. With that thing you could do rich and colorful interfaces. Buttons, edit fields, even status bars and progress bars and all that you need. To start working you only need Python curses installed and urwid folder with its sources (you can transfer whole urwid library with your application as standalone bundle!). It works even under cygwin under Windows XP/7 where is, as we know, no curses ports for Python.

urwid 投资组合

不再是低级的,有时很无聊的curses :)

No more lowlevel, sometimes very boring curses :)

这篇关于在基于 Python 文本的 GUI (TUI) 中输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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