I made a program to add/save data and fetch them, as well as to remove unwanted data. The program works fine in my PC windows 10, I pack the script using command :
pyinstaller -w -i favicon.ico main.py
Edited:( I expected my script to add/save new entries to database as well as to delete saved entries when running the script on other PCs as it is working on my PC )
and I tried it in my PC, the results are satisfied, but when I moved it to another PC, the program is working and is opening, except some its functions won't work, as it passes Try condition, like it won't save new entries and won't delete saved entries in the database, I used SQlite3 as database for the program.
I use try and except in my code for both delete and save functions. (In other PC) When I try to save a new entry the except condition fires and pups up to the screen, which means it didn't work.
Save Function:
def addnewcolor(self):
try:
self.fb = open(self.filename, 'rb')
self.fb = self.fb.read()
self.conn = sqlite3.connect('color_group.db')
self.c = self.conn.cursor()
self.g = "INSERT INTO color_numbers VALUES (?, ?, ? )"
self.val = [(self.main_entry.get(), self.color1_box.get(), self.fb)]
self.c.executemany(self.g, self.val)
if self.c.rowcount > 0:
self.conn.commit()
# clear entry boxes
self.main_entry.delete(0, END)
self.color1_box.delete(0, END)
self.lab.grid_remove()
self.conn.close()
messagebox.showinfo("", "new color has been saved")
self.add_windo.destroy()
self.extra()
except:
self.add_windolaaab = Label(self.ma_fra_main,font=("Hlevetical", 12),
text=("Something went wrong..!"), bg="white")
self.add_windolaaab.grid(row=10, column=3, padx =10, sticky="w")
Update: Delete Function:
def delete_color(self):
self.conn = sqlite3.connect('color_group.db')
self.c = self.conn.cursor()
if self.color_id.get() == '':
messagebox.showerror("", "Insert Correct Value")
self.delete_windo.destroy()
self.open_color()
self.delete_windo.destroy()
try:
self.c.execute("DELETE from color_numbers WHERE id_name like ?", (self.color_id.get(),))
if self.c.rowcount >0:
self.conn.commit()
messagebox.showinfo("", "Deleted")
self.delete_windo.destroy()
self.open_color()
except :
messagebox.showerror("", "Oops! Something Went Wrong..")
self.delete_windo.destroy()
self.open_color()
finally:
self.conn.commit()
self.conn.close()
CodePudding user response:
I found it, I am a newbie I know it, I was testing the script on my PC and the script located on desktop which is running good, the problem was that when I moved the script to another PC I quickly copy all files to C drive located at C:\Program Files which in the end requires Administrative Permission to make it work with all it's functions, I think that database didn't function because I didn't give Admin Permission to the script in first place.
I already tried with giving admin permission to the program and it is working now. The solution is easy, wich is to auto give a Admin permission.
Here are the steps: Right click on the .exe file and navigate to Properties then on the Properties window navigate to Compatibility then check the box which is say "Run this Program as Administrative", this works with me.
Thank you so much for your contribution and replies.