好吧,我现在用的诅咒写一个Python应用程序,我想中心我从文件终端窗口中的文字,你可以使用这个Python的诅咒让x和y
curses.LINES and curses.COLS
我得到的x和y得到这个从here
我猜他们返回x和y为整数
这里是我正在做这个
screen.addstr(curses.LINES, curses.COLS, 'Please enter a number...', curses.color_pair(1))
但是当我运行程序我得到这个
Traceback (most recent call last):
File "main.py", line 102, in <module>
main()
File "main.py", line 47, in main
screen.addstr(curses.LINES/2, curses.COLS/2, 'Please enter a number...', curses.color_pair(1))
TypeError: integer argument expected, got float
我除以2得到的中心,但它不断抛出错误
在python 3中,将一个整数除以2会给你一个float而不是int。尝试使用'//'(整数除法)而不是'/'(浮点除法)。 – khelwood
工作,但它不是集中文本 – 112madgamer
因为你没有考虑到文本本身的长度。你现在正在做的是集中文本的_start_。 – BlackJack