我只想在 Tkinter 標簽上用紅色 * 著色,以表明該欄位是必需的。我嘗試了以下方法:
import colorama
from colorama import Fore, Style
colorama.init()
date_label = Label(my_frame, text=f"Date: {Fore.RED} * {Style.RESET_ALL})"
date_label.pack()
這是輸出:
Date: [][31m*
我知道你可以用 fg 給標簽上色,但我想嘗試只給星號上色。
我也嘗試過 ANSI 代碼,因為它給出了相同的輸出。
順便說一句,我在 Windows 上。
uj5u.com熱心網友回復:
您可以嘗試組合 2 個不同顏色的標簽:
from tkinter import *
Root = Tk()
Date = Label(Root, text="Date: ", fg="black")
Asterick = Label(Root, text="*", fg="red")
Date.grid(row=0, column=0)
Asterick.grid(row=0, column=1)
Root.mainloop()
*無需彩繪
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/330427.html
