格式化 Python 字符串输出
我目前正在编写一个计算器,我希望以视觉上吸引人的形式显示结果。该程序目前只有一个命令行界面,但我一直在尝试找到一种方法来利用它显示的结果执行各种操作。例如,我想让它以更大的字体大小、与系统默认字体不同的字体,甚至下标和上标来显示结果。据我所知,做这些事情的最好方法是引入一个 GUI 并使用像 wxPython 这样的东西,而使用 Unicode 代码点只能解决部分问题。此外,由于各种原因,我只想暂时在命令行中运行该程序。
I'm writing a calculator currently and I'd like to have results displayed in a visually appealing form. The program just has a command line interface for the moment, but I've been trying to find a way to do various things with the results it displays. For example, I'd like to have it display the result in a bigger font size, a different font than system default, and even subscripts and superscripts. From what I could find, the best way to do such things would be if I introduced a GUI and used something like wxPython, and using Unicode code points can only resolve part of the issue. Moreover, for various reasons, I'd just like to have the program in command line for the moment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您无法使用命令行来完成此操作,但您可以查看 curses。我建议为这类事情选择一个 GUI。它真的不太难学,Python 内置的 Tkinter 非常适合入门。 Tkinter 有很多好的资源。以下是我喜欢的一些:
WxPython 非常出色,但如果您刚刚开始,我的建议是从 Tkinter 开始。其他人可能不同意......
编辑
我只记得运行过 Windows 的 console 模块。我怀疑它不会给你你想要的东西,但至少它就在那里。
I don't think you can accomplish this with the command line, but you might check out curses. I would suggest picking up a GUI for this sort of thing. It's really not too hard to learn and Python's builtin Tkinter is perfectly functional for getting started. There are many good resources for Tkinter. Here are a few I like:
WxPython is excellent, but if you are just getting started my suggestion would be to start with Tkinter. Others might disagree...
EDIT
I just remembered running across the console module for Windows. I suspect it won't won't get you what you want, but at least it's out there.
如果您在命令行上运行此命令,我几乎可以肯定您无法执行任何操作来覆盖用户设置的字体首选项。在 Windows 和 Linux 中,命令行的字体设置都是用户控制的,我怀疑您是否可以在没有
sudo
访问权限的情况下更改它。鉴于您正在编写一个计算器,我认为用户不会希望将其作为sudo
运行 - 我当然不想使用sudo 运行像计算器这样简单的东西
权限。要求这样做会让用户认为您在进行恶意活动If you're running this on the command line, I'm almost certain that there's nothing you can do to override the font preferences set by the user. In both windows and Linux, the font settings of the command line are user controlled, and I doubt that you can change it without
sudo
access. Seeing as you're writing a calculator, I don't think a user would want to run it assudo
- I certainly wouldn't want to run something as simple as a calculator withsudo
privileges. To require that would make the user think that you are up to something malicious