简体   繁体   English

如何使用 Python 将文本写入具有不同字体大小的文件?

[英]How to write text into a file with different font-sizes using Python?

How to write Text into a File using Python, where different parts of the Text has different font-size (Title, Sub-Title, content).如何使用 Python 将文本写入文件,其中文本的不同部分具有不同的字体大小(标题、副标题、内容)。 How to place a picture in the file using Python?如何使用 Python 在文件中放置图片?

Python is a programming language capable of manipulating text as variables. Python 是一种能够将文本作为变量进行操作的编程语言。 It does not provide a graphics engine to achieve what you are asking.它不提供图形引擎来实现您的要求。

You need to decide which output format you want your file to be in, example: .html and then format the output as such.您需要决定您希望文件采用哪种输出格式,例如:.html,然后将输出格式设置为这样。

For example, you can create a python file in html like this:例如,您可以像这样在 html 中创建一个 python 文件:

file_handle = open("test.html", "w+b")
html = "<h1>I am a big header</h1><h2>I am a smaller header</h2><h6>I am the smalles header</h6>"
file_handle.write(html)
file_handle.close()

Next, navigate to your folder and open test.html in any browser.接下来,导航到您的文件夹并在任何浏览器中打开 test.html。

As for the images, I suggest you go to:至于图片,我建议你去:

[1]: http://www.w3schools.com/html/html_images.asp [1]:http://www.w3schools.com/html/html_images.asp

Good luck!祝你好运!

for the text, I would write out different lines try this using turtle:对于文本,我会写出不同的行,尝试使用乌龟:

h1 = 10
txt = 5
turtle.write('<example',font('Arial,h1,'normal')

so on and so on.等等等等。 as for the images, I don't know.至于图片,我不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 你如何在 Python 中使用 BeautifulSoup 忽略其他人的同时获取特定的“字体大小”? - How do you grab specific "font-sizes" while ignoring others using BeautifulSoup in Python? Python程序读取一个文本文件,然后将其内容写入另一个文件,不同大小的边距,由用户输入 - Python Program to Read in a File of Text and then Write its Contents in Another File, with Margins of Different Sizes, Input By User 如何将不同大小的整数写入文件 - How to write integers with different sizes to a file python图中的不同字体大小 - Different font sizes in python plot Tkinter在同一文本上有2种不同的字体大小 - Tkinter have 2 different font sizes on the same text 如何通过在python中使用glob.glob从具有不同名称的多个输入文本文件写入多个输出文本文件? - How to write multiple output text file from multiple input text file with different name by using glob.glob in python? 在Python中的一个图例中使用两种不同的文本大小 - Using two different text sizes in one legend in Python 使用Python编写文本文件 - Write a text file using Python Python:Matplotlib:如何在其中打印一个具有不同大小的文本? - Python: Matplotlib: how to print ONE text with different sizes in it? 将多个不同大小的数组写入文本文件 - Write multiple Arrays, of various sizes, into a text file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM