Writing to a .txt file using Python and SQLite3 Writing to a .txt file using Python and SQLite3 tkinter tkinter

Writing to a .txt file using Python and SQLite3


Your problem/error lies in the line write.write("-----CUSTOMER INVOICE-----", "\n".join(str(x) for x in results)). The comma in write.write() creates 2 arguments, where the write-function expects only one (the text to write). I've adapted your code, so it still writes all results to seperate lines.

def PrintOrder(self):    orderid = self.OrderIDEntry.get()    productid = self.ProductIDEntry.get()    quantity = self.QuantityEntry.get()    with sqlite3.connect("LeeOpt.db") as db:        cursor = db.cursor()        search_order = ('''SELECT * FROM Orders WHERE OrderID = ?''')        cursor.execute(search_order, [(orderid)])        results = cursor.fetchall()        if results:            for i in results:                write = open("orderinvoice.txt","w")                write.write("-----CUSTOMER INVOICE-----")                for x in results:                    write.write(str(x))                tkinter.messagebox.showinfo("Notification","Invoice generated successfully.")                self.ClearEntries()        else:            tkinter.messagebox.showerror("Error", "No order was found with this OrderID, please try again.")            self.ClearEntries()