Home > other >  For help, python treeview interlaced jump color problem
For help, python treeview interlaced jump color problem

Time:11-18


 # add dataTree. Insert (" ", 0, text=", line1, "values=(" aaa", "18", "60", "50"), tags="aa") 
Tree. Insert (" ", "end", the text=", line1, "values=(" BBB", "18", "60", "50"), tags="bb")
Id=tree. Get_children () # id return to insert all of the data tuple
The item=tree. The item (id [0])
Print (item)
Print (tree. The item (id [1]))
Print (item [" values "])
Tree. Tag_configure (" bb ", background="red")
Def func (event) :
Id=event. The widget. The selection ()
Print (id)
Print (tree. The item (id) [" values "] [1])
Age=tree. The item (id) (" values ")
Print (age [2])
Tree. Bind (" & lt; & gt;" , the func)

Tree. Pack ()
Win the mainloop ()

# the following code fragment is doing DBF keyword query tool interface
Def tree_v (self, tr) : # set the style of the tree,
The items=tr. Get_children ()
For I in range (len (items) :
If I % 2==0:
Tr. Item (items [I], tags=(' row '))
The else:
Tr. Item (items [I], tags=(' row1 '))
Tr. Tag_configure (' row 'background=' # eeeeff ', the font="bold")
Tr. Tag_configure (' row1 'background=' # f0f8ff ') # with "red" didn't effect such as
why the same code, the computer in his home run can be interlaced show different color, unit computer run does not display the color, the font display (operating system, the same home is py3.7, unit is 3.8 at the beginning of computer

CodePudding user response:

Do you have a problem solved, I have recently encountered the same problem with you, I am using python3.8.2 version, reference books are HongJinKui "Python GUI design tkinter novice programming", the book examples in the application of 18-3 quarter ch18_6. Py code that can run on my computer, but is not alternating color, at first I thought it was my code type is wrong, then check line by line, completely like the book, but is not alternating colors, my kao down other people's code to run from the Internet is also the same result, don't know is why

CodePudding user response:

# ch18_6. Py
The from tkinter import *
The from tkinter. TTK import *

Root=Tk ()
Root. Title (" ch18_6 ")

StateCity={" Illinois ":" Chicago ", "California" : "Los Angeles",
"State" : "Houston", "Washington" : "Seattle,"
"Jiangsu province", "nanjing", "shandong province", "Qingdao",
"Guangdong province", "guangzhou", "fujian province", "xiamen"}

Tree=the Treeview (root, the columns=(" cities "))

Tree. Heading (" # 0 ", the text="State")
Tree. Heading (" cities ", the text="City")

Tree. The column (" cities ", the anchor=CENTER)
Tree. Tag_configure (" evenColor ", background="lightblue")
RowCount=1

For the state in stateCity. Keys () :
If the rowCount % 2==1:
Tree. Insert (" ", the index=END, text=the state that values=stateCity [state])
The else:
Tree. Insert (" ", the index=END, the text=the state that values=stateCity [state], tags=(" evenColor "))
RowCount +=1

Tree. Pack ()

Root. Mainloop ()

CodePudding user response:

I can try Python3.6.5 3.7.6 and 3.8.2 can't

CodePudding user response:

Do you solved? I also found this problem, the 3.6 stable color, 3.7 basic will not change color, see the equipment
  • Related