更改Tkinter中单元格的背景颜色?

时间:2018-10-03 18:01:52

标签: python tkinter cell background-color

我看到可以更改行的背景颜色,但是可以更改单元格的背景颜色吗?

我需要“忙碌”单元格的颜色为红色。

运行如下:

Codigo en ejecucion

代码就是这样

from tkinter import *
from tkinter.ttk import *
import tkinter.messagebox

class App(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.CreateUI()
        self.LoadTable()
        self.grid(sticky = (N,S,W,E))
        parent.grid_rowconfigure(0, weight = 1)
        parent.grid_columnconfigure(0, weight = 1)

    def CreateUI(self):
        tv = Treeview(self)
        tv['columns'] = ('First', 'Second')
        tv.heading("#0", text=' ', anchor='w')
        tv.column("#0", anchor="w")
        tv.heading('First', text='First')
        tv.column('First', anchor='center', width=100)
        tv.heading('Second', text='Second')
        tv.column('Second', anchor='center', width=100)
        tv.grid(sticky = (N,S,W,E))
        self.treeview = tv
        self.grid_rowconfigure(0, weight = 1)
        self.grid_columnconfigure(0, weight = 1)


    def LoadTable(self):
        agente1 = self.treeview.insert('', 'end', text="Agente1",)
        self.treeview.insert(agente1, 'end', text="Availability", values=('Busy',
                            'Insert'))

def main():
    root = Tk()
    App(root)
    root.mainloop()

if __name__ == '__main__':
    main()

0 个答案:

没有答案