Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\USER1\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:/Users/USER1/AppData/Local/Programs/Python/Python37/newWidget.py", line 54, in clickedEvaluate
txt.insert(END,s[i] +">>>>>>>>>" + Dicesim + "\n")
TypeError: can only concatenate str (not "StringVar") to str
the text above shows the error message
Dicesim=StringVar()
def clickedEvaluate():
if txt1.get()=='':
messagebox.showerror('Empty entry', 'You have not entered the required first text for comparison')
txt1.focus()
else:
combo = Combobox(window)
combo['values']= ('Dice', 'Bigram', 'Trigram', 'Set-Based','NS-Sim')
combo.current(0) #set the selected item
combo.grid(column=0, row=4)
file=open('db_word.txt','r')
s=file.readlines()
txt = ScrolledText(window,width='50',height='10',wrap=WORD)
txt.grid(column=1,row=6)
#txt.pack()
if combo.get()=='Dice':
for i in range(20):
Dicesim.set(dice(txt1.get(),s[i]))
txt.insert(END,s[i] +">>>>>>>>>" + Dicesim + "\n")
txt.yview(END)
The expected result is to display
's[i] +">>>>>>>>>" + Dicesim + "\n"'. this in a line as dice() is performed, the StringVar, Dicesim is not recognised in txt.insert method.
Related
Alrighty so this is the error I get:
AttributeError: 'DES' object has no attribute 'summary_output'
So this is what I am trying to do.
When I am on this frame, I am creating a text variable that is then sent to a set class.
class upload_csv(Frame):
def __init__(self, master):
self.master = master
self.frame = tk.Frame(self.master, width=250, height=160, bg='white')
self.upload_csv_btn = Button(
self.frame,
text="Add Data Source",
fg="DodgerBlue4",
font=("Graph Type", 15),
height=1, width=20,
borderwidth=2,
relief="groove",
command=self.upload)
self.upload_csv_btn.place(x=10, y=10)
self.frame.pack()
def upload(self):
global text
self.xvalues = []
self.yvalues = []
self.xyvalues = []
self.header = []
filename = filedialog.askopenfilename()
if len(filename) != 0:
print('Selected:', filename)
with open(filename) as file:
csvreader = csv.reader(file)
self.header.append(next(csvreader))
for row in csvreader:
if len(row) == 3:
self.xvalues.append(int(row[0]))
self.yvalues.append(int(row[1]))
self.xyvalues.append(int(row[2]))
text = (
self.header[0][0]+ ": " + str(self.xvalues).replace('[','').replace(']','') +
"\n\n" + self.header[0][1] + ": " + str(self.yvalues).replace('[','').replace(']','') +
"\n\n" + self.header[0][2] + ": " + str(self.xyvalues).replace('[','').replace(']',''))
elif len(row) == 2:
self.xvalues.append(row[0])
self.yvalues.append(row[1])
text = (
self.header[0][0] + ": " + str(self.xvalues).replace('[','').replace(']','') +
"\n\n" + self.header[0][1] + ": " + str(self.yvalues).replace('[','').replace(']',''))
# -------------------------------------------------------------------------
s = Set(text)
s.set_summary()
#-----------------------------------------------------------------------
Using the upload class, I am sending the variable by calling the set class, and calling the set_summary method. With this set class, I am setting the string as a an object item, that is then send to my DES class. I want this item to be set on a tk textbox element as a summary. I receive the text fine in the DES class, but I get the following error when trying to modify the summary element.
The error I get:
Traceback (most recent call last):
File "C:\Users\***\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Users\***\Documents\Workspace\***\***\view\upload_csv.py", line 115, in upload
s.set_summary()
File "C:\Users\***\Documents\Workspace\***\***\view\Set.py", line 14, in set_summary
s.set_summary_text()
File "C:\Users\***\Documents\Workspace\***\***\view\test.py", line 164, in set_summary_text
print(self.summary_output)
AttributeError: 'DES' object has no attribute 'summary_output'
My set class:
class Set:
def __init__ (self, summary):
self.summary = summary
def set_summary(self):
print(self.summary)
s = DES(self.summary)
s.set_summary_text()
My DES Class:
class DES(Frame):
def __init__(self, summary):
self.summary = summary
def createFrame(self, master):
self.frame = tk.Frame(master, width=750, height=968,bg='white')
self.summary_output = tk.Text(
self.frame,
height=8,
width=78,
bg="gray95",
borderwidth=2,
relief="groove",
font=("Arial", 12))
self.summary_output.configure(state='disabled')
self.summary_output.place(x=20, y=610)
self.frame.pack()
def set_summary_text(self):
print(self.summary)
print(self.summary_output)
self.summary_output.configure(state='normal')
self.summary_output.delete('1.0', END) # Remote all text
self.summary_output.insert('end',self.summary)
self.summary_output.configure(state='disabled') #Make text widget read only
def main():
global root
root = tk.Tk()
# app = DES(root)
# app = DES.createFrame(root)
s = DES("")
s.createFrame(root)
root.mainloop()
if __name__ == '__main__':
main()
Edit:
So after trying the answer I got the following error, all I did was add the suggestion:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\***\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Users\***\Documents\Workspace\\***\\***\view\upload_csv.py", line 115, in upload
s.set_summary()
File "C:\Users\\***\Documents\Workspace\\***\view\Set.py", line 22, in set_summary
s.createFrame(root)
File "C:\Users\\***\Documents\Workspace\\***\view\test.py", line 120, in createFrame
self.canvas.draw() # Create the graph canvas
File "C:\Users\\***\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 11, in draw
self._master.update_idletasks()
AttributeError: 'str' object has no attribute 'update_idletasks'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\\***\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Users\\***\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\backends\_backend_tk.py", line 235, in filter_destroy
self._master.update_idletasks()
AttributeError: 'str' object has no attribute 'update_idletasks'
So I remove the matplot graph and got this error:
So maybe the graph is interfering? Im not sure, I need the graph.
The summary_output in DES class, will be defined in the
createFrame method.
You first instatiated from the DES class in the Set.set_summary()
method and then called the set_summary_text() method, which it uses
the summary_output. That's not correct, since the summary_output has not been defined, yet.
You should first, call the createFrame() method to define the
summary_output attribute and then call the set_summary_text() to
use summary_output.
Do something like this, in the Set class:
class Set:
def __init__ (self, summary):
self.summary = summary
def set_summary(self):
global root
print(self.summary)
s = DES(self.summary)
s.createFrame(root)
s.set_summary_text()
Or do whatever you think it's best for you, but you should define the summary_output first, and then print or use it.
I want to create multiple databases but I don't know how I can make it
this is python code:
# 1 - for import data in listbox
def clear_item_list():
items.delete(0, END)
# 2 - for import data in listbox
def fill_item_list(items):
for item_ in items:
items.insert(END, item_)
# 3 - for import data in listbox
def item_list_view():
clear_item_list()
items = app.data_1.view()
fill_item_list(items)
# and that for placement data in entries
def get_selected_row_item(event):
global selected_item
if len(items.curselection()) > 0:
index = items.curselection()[0]
selected_item = items.get(index)[:]
item_name.delete(0, END)
item_name.insert(END, selected_item[1])
item_price.delete(0, END)
item_price.insert(END, selected_item[2])
items.bind("<<ListboxSelect>>", get_selected_row_item)
This code is for making a table:
"CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY , Namee VARCHAR , price INTEGER )"
I don't have any idea this is my problem or not, because when I wanna use price, type that data is string and python raise this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Green\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "D:\python\WindowsProject\app\manager\manager_sign_in.py", line 44, in back_to_main_manager
main_screen()
NameError: name 'main_screen' is not defined
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Green\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "D:\python\WindowsProject\app\manager\sign.py", line 33, in back_to_main_mngr
main_screen()
NameError: name 'main_screen' is not defined
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Green\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "D:\python\WindowsProject\app\main.py", line 33, in user_sign
user_screen()
NameError: name 'user_screen' is not defined
Traceback (most recent call last):
File "D:\python\WindowsProject\app\main.py", line 4, in <module>
from app.user.user_sign_in import *
File "D:\python\WindowsProject\app\user\user_sign_in.py", line 240, in <module>
user_screen()
File "D:\python\WindowsProject\app\user\user_sign_in.py", line 236, in user_screen
item_list_view()
File "D:\python\WindowsProject\app\user\user_sign_in.py", line 55, in item_list_view
fill_item_list(items)
File "D:\python\WindowsProject\app\user\user_sign_in.py", line 48, in fill_item_list
items.insert(END, item_)
TypeError: 'str' object cannot be interpreted as an integer
and this is input data:
(1, 'pizza', '6')
if you can help me pls say to I give you more data about that if you need
The issue is on the below function:
def fill_item_list(items): # <- items is passed argument
for item_ in items:
# "items" below is expected to be an instance of tkinter Listbox
# but it is actually the passed argument (a list object)
items.insert(END, item_)
You used same name on the passed argument as the tkinter Listbox.
Use another name for the passed argument:
def fill_item_list(data): # used "data" instead of "items"
for item_ in data:
items.insert(END, item_)
UPDATE: I know the token error only and I don't understand what is happening as I encrypt and decrypt with the same key?
Error at hand:
Exception in Tkinter callback #Don't understand this callback as this is to do with the cryptography module I am using
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
return self.func(*args)
File "/Users/James/Documents/Programming/PasswordManager/main.py", line 190, in see
decrypt = f.decrypt(item[1].encode('utf-8'))
File "/Users/James/Documents/Programming/venv/lib/python3.8/site-packages/cryptography/fernet.py", line 75, in decrypt
timestamp, data = Fernet._get_unverified_token_data(token)
File "/Users/James/Documents/Programming/venv/lib/python3.8/site-packages/cryptography/fernet.py", line 107, in _get_unverified_token_data
raise InvalidToken
cryptography.fernet.InvalidToken
b'gAAAAABgY3KXoeeegS8RPHdvXTH6_GQ_EPfgdqZqIwP4XL-hIyEk3BcxV3y0o_quNPFyHeTdkv7Pk9MmnEIL1XeXlEfuUQNJ_e_dIsAr2ZvLGpDT1Y6I6Qvzat5aAf7Z0624O4BeAFNf
Original Question
I am making a password manager, I started by using files and some suggested sqlite3 so I have started to use it so I can add the function of rewriting the passwords but I keep getting two errors that have really confused me,
The table sqlite table:
c.execute("""CREATE TABLE passwords (passwordTitle text,generatedPassword text)""")
I encrypt the password using this function, this works and inserts into database:
def submited():
# Call the password generator
setPassword()
# Get user input from the entry
usrinput = userInput.get()
# Set a splitter for writing to the file
# If passwordenc.txt exists:
if os.path.isfile('data.db'):
# Open passwordenc.txt and set it as password_file
# Encrypt the combo
genPasswordEnc = f.encrypt(generatePassword.encode('utf-8'))
c.execute("INSERT INTO passwords VALUES(?,?)", (usrinput, genPasswordEnc))
conn.commit()
# If passwordenc.txt does not exist:
and I decrypt it using this function:
def see():
menu.destroy()
seeWin = Tk()
seeWin.geometry('1250x500')
# Same size will be defined in variable for center screen in Tk_Width and Tk_height
Tk_Width = 1250
Tk_Height = 500
# calculate coordination of screen and window form
x_Left = int(seeWin.winfo_screenwidth() / 2 - Tk_Width / 2)
y_Top = int(seeWin.winfo_screenheight() / 2 - Tk_Height / 2)
# Write following format for center screen
seeWin.geometry("+{}+{}".format(x_Left, y_Top))
seeWin.title('See Password')
seeFrame = tk.Frame()
listbox = tk.Listbox(seeFrame, height='30', width='135')
listbox.pack(side=LEFT, fill=BOTH)
scrollbar = tk.Scrollbar(seeFrame, )
scrollbar.pack(side=RIGHT, fill=Y)
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
if os.path.isfile('data.db'):
c.execute('SELECT * FROM passwords')
password_list = c.fetchall()
for item in password_list:
item = str(item)
itemSplit = item.split(',')
leng = len(itemSplit[1])-2
itemCut = itemSplit[1][:leng].encode('utf-8')
print(itemCut)
decrypt = f.decrypt(itemCut)
print(decrypt)
listbox.insert(END, str(decrypt))
print("Decrypted pass: ", decrypt)
But I keep getting this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/James/Documents/Programming/venv/lib/python3.8/site-packages/cryptography/fernet.py", line 102, in _get_unverified_token_data
data = base64.urlsafe_b64decode(token)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/base64.py", line 133, in urlsafe_b64decode
return b64decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Invalid base64-encoded string: number of data characters (141) cannot be 1 more than a multiple of 4
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
return self.func(*args)
File "/Users/James/Documents/Programming/PasswordManager/main.py", line 190, in see
decrypt = f.decrypt(itemCut)
File "/Users/James/Documents/Programming/venv/lib/python3.8/site-packages/cryptography/fernet.py", line 75, in decrypt
timestamp, data = Fernet._get_unverified_token_data(token)
File "/Users/James/Documents/Programming/venv/lib/python3.8/site-packages/cryptography/fernet.py", line 104, in _get_unverified_token_data
raise InvalidToken
cryptography.fernet.InvalidToken
And I don't understand what is throwing this error as when using a .txt file
When my program is compiled via pyinstaller I run into this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.py", line 1892, in __call__
File "editSpeakers.py", line 67, in <lambda>
File "editSpeakers.py", line 52, in autoUpdateSpeakers
File "tkinter\__init__.py", line 3043, in get
_tkinter.TclError: invalid command name ".!editspeakers.!canvas.!frame.!entry"
I presume this is a tkinter problem but I have no idea how to fix it and it only shows up when ran via pyinstaller not when ran via the IDE
Code Snippets:
def populate(self):
speakers = main.openSpeakers()
speakersList = sorted(speakers.items())
numRows = len(speakers) + 3
for i in range(numRows):
self.key = tk.Entry(self.frame, width=20, fg="blue", font=("Arial", 16, "bold"))
self.value = tk.Entry(self.frame, width=20, fg="blue", font=("Arial", 16, "bold"))
self.key.grid(row=i, column=0)
self.value.grid(row=i, column=1)
EditSpeakers.entryList.append([self.key, self.value])
try:
self.key.insert(0, speakersList[i][0])
self.value.insert(0, speakersList[i][1])
except IndexError: pass
def autoUpdateSpeakers(self, root):
speakers = dict()
try:
for key, value in EditSpeakers.entryList:
if key.get():
speakers[key.get()] = value.get()
with open("speakers.json", "w") as f:
json.dump(speakers, f, indent=4)
except Exception as e: print(e) ## << Error happening here
finally: root.destroy()
You can find my full code here
I don't know why this is giving me an attribute error. I want my blah() function to shuffle the cards. I'm calling the builtin function shuffle() from random.
Error:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1489, in __call__
return self.func(*args)
File "gui1.py", line 105, in blah
shuffle(cards)
AttributeError: Button instance has no __call__ method
Here's the code snippet:
def blah():
global card_count
global path
shuffle(cards)
card_count = 0
path = generate_paths(cards)
print "Cards Shuffled"
shuffle = Button(frame_buttons, text = "SHUFFLE",height = 2, width = 10,command =blah)
shuffle.grid(row = 2 , padx = 40, pady = 40)
shuffle is the name of the function in random. However, it's also the name of the Button. Change the Button's name to something like shuffle_button and you should be fine.