我正在努力让我的方法正常工作。我考虑过使用lambda我为另一个问题所做的函数并且有效,但是在这里它似乎不起作用。我正在尝试将函数更改为方法,但由于某种原因,我的方法无法正常工作,因为它没有引用树。我尝试过使用一个lambda函数,尽管它不起作用。
我的错误:
NameError: name 'tree' is not defined
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
return self.func(*args)
File "/home/bitvivaz/Documents/Software Development/Python/PasswordManager/mainFrame.py", line 54, in select
print([tree.item(x) for x in tree.selection()])
NameError: name 'tree' is not defined
这是我的代码:
import tkinter as tk
import tkinter.ttk as ttk
from encryption import encrypted_password, decrypt_password
import backend as db
def get_credentials(tree):
'''Retrieves all credentials from the database and inserts it into the tree widget'''
for row in db.show_credentials():
tree.insert("", 'end', text=row['name'], values=(
row['username'], decrypt_password(row['password'])))
class MainframeApp:
def __init__(self, master=None):
# build ui
frame_main = ttk.Frame(master)
frame_main.config(height='600', width='600')
frame_main.grid()
# Creates tree widget
tree = ttk.Treeview(frame_main)
tree["columns"] = ("one", "two")
tree.column("#0")
tree.column("one")
tree.column("two")
tree.heading("#0", text="Website")
tree.heading("one", text="Username")
tree.heading("two", text="Password")
tree.grid(padx='5', pady='5', rowspan='20')
get_credentials(tree)
tree.bind("<<TreeviewSelect>>", self.select, "+")
button_add = ttk.Button(frame_main)
MMMHUHU
相关分类