Table separator lines are not displayed. I need separator lines between rows and columns. What is the problem?
def show_submenu_102(self):
# creat manager Fiscal year
sub_102 = tk.Toplevel(self.root)
sub_102.title("Fiscal year management")
sub_102.geometry("560x320")
sub_102.configure(bg="#9fe1fd")
sub_102.focus_force()
# Create a blue box for buttons (150 pixels wide)
blue_frame = tk.Frame(sub_102, bg="#9fe1fd", width=150, height=500)
blue_frame.place(relx=0.99, rely=0, anchor="ne")
# Create a white box with a distance from the right side of the blue box
white_frame = tk.Frame(sub_102, bg="white", width=600, height=400)
white_frame.place(relx=0.01, rely=0.01, anchor="nw")
# Headlines
columns = ("Active", "Tax Percentage", "Fiscal Year", "Row")
tree = ttk.Treeview(white_frame, columns=columns, show="headings")
for col in columns:
tree.heading(col, text=col , anchor="center")
tree.column(col, width=100, anchor="center" , stretch=False) # Adjust column width
tree.pack(fill="both", expand=True)
# Table settings
style = ttk.Style()
style.theme_use("default")
style.configure("Treeview",
background="white",
foreground="black",
rowheight=25,
font=('Arial', 10),
fieldbackground="white",
bordercolor="black", # Border color
borderwidth=2, # Outer rim thickness
highlightthickness=2, # Thickness of internal dividing lines
highlightcolor="black" #Color of the dividing lines
)
# Column capital configuration
style.configure("Treeview.Heading",
background="#9fe1fd",
foreground="black",
font=('Arial', 12, 'bold'),
relief="flat" # Remove prominence
)
# Activating internal dividing lines
style.layout("Treeview", [
('Treeview.treearea', {'sticky': 'nswe', 'border': 1})
])
#_____________________________
# Function to load fiscal years from the database and display in a table
def load_financial_years():
conn = sqlite3.connect('tanbal.db')
cursor = conn.cursor()
try:
# Checking the existence of a table
financial_years
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='financial_years'")
if cursor.fetchone():
#Getting fiscal years from a table
cursor.execute("SELECT year, tax_rate, is_default FROM financial_years")
years = cursor.fetchall()
# Clearing the table and adding new years
tree.delete(*tree.get_children())
for index, (year, tax_rate, is_default) in enumerate(years, start=1):
tree.insert("", "end", values=("Active" if is_default else "Inactive", tax_rate, year, index))
else:
print("The financial_years table does not exist.")
except sqlite3.Error as e:
print(f"Error loading fiscal years: {e}")
finally:
conn.close()
# Calling the function to load fiscal years
load_financial_years()
# The rest of the functions are sub-sets.
# Creating buttons in a blue box
add_button = tk.Button(blue_frame, text="Add", command=add_function, bg="white", fg="black")
add_button.pack(pady=10)
edit_button = tk.Button(blue_frame, text="edite", command=edit_function, bg="white", fg="black")
edit_button.pack(pady=10)
delete_button = tk.Button(blue_frame, text="delete", command=delete_function, bg="white", fg="black")
delete_button.pack(pady=10)
choice_button = tk.Button(blue_frame, text="select", command=choice_function, bg="white", fg="black")
choice_button.pack(pady=10)
move_button = tk.Button(blue_frame, text="Carryover to next year", command=move_function, bg="white", fg="black")
move_button.pack(pady=20)
#Create an exit button in a blue box
exit_button = tk.Button(blue_frame, text="Esc", width=10, height=2, command=lambda: [self.root.focus_force(), sub_102.destroy()])
exit_button.pack(pady=5)
# Keyboard shortcuts
sub_102.bind('<Insert>', lambda event: add_function())
sub_102.bind('<Escape>', lambda event: [self.root.focus_force(), sub_102.destroy()])
sub_102.bind('<F2>', lambda event: edit_function())
sub_102.bind('<Control-Delete>', lambda event: delete_function())