我想創(chuàng)建一個 HTML 頁面,用 n 種不同的顏色說 Hello World n 次,其中 n 是從不同存儲庫中的配置文件中讀取的,并通過 python 程序生成頁面,我們可以使用 Javascript 來表示顏色會更有幫助。我可以顯示 hello world n 次,但我不知道如何更改顏色。這是我到目前為止編寫的代碼: import ConfigParser import webbrowser configParser = ConfigParser.RawConfigParser() configParser.read("/home/suryaveer/check.conf") num = configParser.get('userinput-config', 'num') num2 = int(num) hello = """"hello world """ hello2 = hello*num2 message = """<html><head> </head><body><p>"""+hello2+"""</p></body> </html>""" f = open('x.html', 'w') f.write(message*num2) f.close() webbrowser.open("file:///home/suryaveer/x.html")
2 回答

婷婷同學_
TA貢獻1844條經(jīng)驗 獲得超8個贊
為了給每個“hello world”設置不同的樣式,它們必須位于不同的 HTML 塊中。您可以實現(xiàn)將“hello world”的每個實例包裝在span.
hello = """"<span>hello world </span>"""
這將不會向您的頁面添加任何可見內(nèi)容,但將允許單獨訪問每個實例并為其設置樣式。
如果你想在 Python 中完成這一切,你可以style在創(chuàng)建它時向 span添加一個內(nèi)聯(lián)。
colors = [color1, color2, ... colorN] # List of n colors
hello2 = ""
for c in colors:
hello2 += """"<span style='color:{};'>hello world </span>""".format(c)
如果您需要更多幫助或想了解其他選項(Javascript),請告訴我
添加回答
舉報
0/150
提交
取消