TypeError: finance_tracker.create_widgets..() missing 1 required positional argument: ‘col’

  Kiến thức lập trình

I am getting an error in the following code

class finance_tracker:
def init(self, root):
self.root = root
self.root.geometry(“1000×550”)
self.root.resizable(False, False)
self.root.title(‘Personal Finance Tracker’)
self.root.iconbitmap(r’C:UsersUSERDesktopSD1_CourseworksCOURSEWORK_03tracker_icon.ico’)
self.FILE_PATH = ‘transaction.json’
self.transactions = self.load_transaction()
self.create_widgets()
self.max_id = max(
transaction[‘id’] for category in self.transactions.values() for transaction in
category) if self.transactions else 0
self.search_transactions()

def create_widgets(self):

    # create label
    display_title = tk.Label(self.root, text="Manage Your Transactions Here!",
                             anchor="center", font=TITLE_FONT_STYLE, bg=BLUE_GRAY)
    display_title.pack()

    # Add Some style
    style = ttk.Style()

    # pick a theme
    style.theme_use('clam')  # themes - defaults, alt, clam, vista

    # configure our treeview colors
    style.configure('Treeview',
                    background='White',
                    foreground='Black',
                    rowheight=25,
                    fieldbackground=ASH_GRAY)
    # change selected color
    style.map('Treeview',
              background=[('selected', BUTTERSCOTCH_ORANGE)])

    # create treeview frame
    tree_frame = tk.Frame(self.root)
    tree_frame.configure(bg=BLUE_GRAY)
    tree_frame.pack(fill=tk.BOTH, expand=True, pady=10)

    # create treeview scroll bar
    tree_scroll = tk.Scrollbar(tree_frame)
    tree_scroll.configure(bg=BLUE_GRAY, relief=tk.FLAT)
    tree_scroll.pack(side=tk.RIGHT, fill=tk.Y)

    # create the tree view
    self.my_tree = ttk.Treeview(tree_frame, yscrollcommand=tree_scroll.set, selectmode=tk.EXTENDED)
    self.my_tree.pack(fill=tk.BOTH, padx=10)

    # defining columns
    self.my_tree['columns'] = (
        'Transaction Type', 'Transaction Category', 'Transaction Amount', 'Transaction Date', 'Transaction ID')

    # configure scroll bars
    tree_scroll.configure(command=self.my_tree.yview)

    # format columns
    self.my_tree.column('#0', width=0, stretch=NO)
    for col in self.my_tree['columns']:
        self.my_tree.column(col, anchor=tk.CENTER, width=120)

    # create headings
    self.my_tree.heading('#0', text='', anchor=tk.W)
    for col in self.my_tree['columns']:
        self.my_tree.heading(col, text=col, anchor=tk.CENTER,
                             command=lambda col: self.sort_by_column(self.my_tree, col, False))

    # create transaction type based striped row tags
    self.my_tree.tag_configure('income_row', background=ROBIN_EGG_BLUE)
    self.my_tree.tag_configure('expense_row', background=VERDIGRIS_BLUE)

    # adding data to the screen
    self.count = 0
    for item in self.transactions.keys():
        for record in self.transactions.get(item):
            if record['type'] == 'Income':
                self.my_tree.insert(parent='', index='end', iid=self.count, text='',
                                    values=(
                                    record['type'], item, f'{record['amount']:,.2f}', record['date'], record['id']),
                                    tags=('income_row',))
            elif record['type'] == 'Expense':
                self.my_tree.insert(parent='', index='end', iid=self.count, text='',
                                    values=(
                                    record['type'], item, f'{record['amount']:,.2f}', record['date'], record['id']),
                                    tags=('expense_row',))
            self.count += 1  # increment counter
def sort_by_column(self, tree, col, reverse):
    for row in tree.get_children():
        data = (tree.set(row, col), row)
        data.sort(reverse=reverse)

        for index in range(len(data)):
            val, row = data[index]
            tree.move(row, '', index)

        tree.heading(col, command=lambda c=col: self.sort_by_column(tree, c, not reverse))

I tried changing the code by changing c=col. But it did not worked

New contributor

Geethaka Sankalpa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT