[英]How do I change the text colour of an active cell in a TkTable in Python?
我在使用Python的tkinter模塊創建的應用程序中使用tktable。
當我選擇一個單元格並輸入它時,文本的顏色是白色的,這很難讀。 例如,如何將此顏色更改為黑色。
我已經改變了'前景'的顏色,但我沒有改變。
self.table = tktable.Table(self, rows=5, cols=5, multiline=0, font=("Helvetica", 10), foreground='Red', background='White', cache=True, colstretchmode='all')
self.table.grid(row=0, column=1, padx=10, pady=10, sticky='e,w')
為找到這條線的人們提供全面的解決方案:
import Tkinter as tk
import tktable
class App(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.parent = parent
self.Main()
self.grid()
def Main(self):
self.table = tktable.Table(self, rows=5, cols=5, multiline=0, font=("Helvetica", 10), foreground='Black', background='White', cache=True, colstretchmode='all')
self.table.tag_configure('active', foreground='black') # <<<ADDED LINE/ SOLUTION
self.table.grid(row=0, column=0, padx=10, pady=10, sticky='e,w')
if __name__ == "__main__":
root = tk.Tk()
app = App(root)
app.mainloop()
選擇單元格進行編輯時,“active”標簽生效。
嘗試類似的東西:
self.table.tag_configure('active', foreground='black')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.