python - 当文本的长度超过 Python 中的窗口大小时,如何打印新行或自动打印新行?
问题描述
当文本的长度超过窗口宽度或超过我限制的长度时,我想打印到新行。"\n" 在这里不起作用,因为我正在使用函数来塑造文本消息。
样本:
input_message = "Hello, world!"
message = text_format(input_message, font, 90, yellow)
# Text Renderer
def text_format(message, textFont, textSize, textColor):
newFont=pygame.font.Font(textFont, textSize)
newText=newFont.render(message, 0, textColor)
return newText
我希望 input_message 会打印如下:
“你好, ”
“世界!” (“世界!”超过窗口宽度)。
如何修改text_format函数来实现呢?
解决方案
您可以使用 CSS 属性text-overflow
该text-overflow
属性指定如何将未显示的溢出内容通知给用户。它可以被剪裁、显示省略号 (...) 或显示自定义字符串。
.container {
white-space: normal;
border: 1px solid #000000;
}
<div class="container">The text-overflow property specifies how overflowed content that is not displayed should be signaled to the user. It can be clipped, display an ellipsis (...), or display a custom string.</div>
推荐阅读
- python - 如何在没有目标值的数据集上使用决策树进行预测?
- python - 使用 PIL 库从 YCbCr 到 RGB 的色彩空间转换?
- ios - 使用 Swift 5.1 for iOS 中的 SwiftUI 使用 RadialGradient 填充动态大小的 Rectangle
- ruby-on-rails - Rails 5 yield 给出重复的内容
- python - 将python文件导入另一个python文件
- python - 使用 Python 和 Selenium 抓取 Instagram 上喜欢帖子的帐户的名称,但仅返回 11 个名称
- r - expss 包可以处理带有加权数据的多个答案问题吗?
- php - PHP 在 Heroku 上连接到 Postgres 时遇到问题
- jenkins - 在 Bash 脚本中,如何退出整个脚本并返回成功
- matlab - 如何使用 fzero() 在 MATLAB 中求解多项式方程?