Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
from tkinter import *
import tkinter as tk
import tkinter.messagebox as tkMessageBox  
import sqlite3

#function to define database
def Database():
    global conn,cursor
    #create person database
    conn=sqlite3.connect("regform.db")
    cursor=conn.cursor()
    #creating person_reg table
    cursor.execute('''
                CREATE TABLE IF NOT EXISTS PERSON(
     pr_id INT AUTO_INCREMENT PRIMARY KEY,
     pr_name VARCHAR(50),
     pr_age VARCHAR(10),
     pr_gender VARCHAR(50),
     pr_email VARCHAR(50),
     pr_phone VARCHAR(50)
     
     )

 ''')





def Registration():
    Database()
    #getting form data
    name1=e1.get()
    age1=e2.get()
    gender1=e3.get()
    email1=e4.get()
    phone1=e5.get()
    #applying empty validations
    if name1=='' or age1=='' or gender1=='' or email1=='' or phone1=='':
        tkMessageBox.showinfo("Warning","fill the empty field")
    else:
        #execute query
        cursor.execute('''
        INSERT INTO PERSON (pr_name, pr_age, pr_gender, pr_email, pr_phone)
        VALUES (?, ?, ?, ?, ?)
    ''', (name1, age1, gender1, email1, phone1))
    conn.commit()
    tkMessageBox.showinfo("Message","Stored successfully")
    conn.close()
window=tk.Tk()
window.geometry('300x200')
window.title("Registration Portal")
#label for the box field
l1=tk.Label(window,text='Person Details')
l2=tk.Label(window,text='Name')
l3=tk.Label(window,text='Age')
l4=tk.Label(window,text='Gender')
l5=tk.Label(window,text="Email")
l6=tk.Label(window,text="Phone")

l1.grid(row=1,column=1)
l2.grid(row=2,column=1)
l3.grid(row=3,column=1)
l4.grid(row=4,column=1)
l5.grid(row=5,column=1)
l6.grid(row=6,column=1)
#create box field
e1=tk.Entry(window)
e2=tk.Entry(window)
e3=tk.Entry(window)
e4=tk.Entry(window)
e5=tk.Entry(window)

e1.grid(row=2,column=2)
e2.grid(row=3,column=2)
e3.grid(row=4,column=2)
e4.grid(row=5,column=2)
e5.grid(row=6,column=2)

#submit button
b=tk.Button(window,text='Submit Here', command=Registration)
b.grid(row=7,column=1)

window.mainloop()


What I have tried:

form is submitted with database connectivity on window executable file
Posted
Updated 24-May-23 2:27am
v2
Comments
Richard MacCutchan 24-May-23 8:30am    
How are you convderting the above script into a Windows executable?

I just converted this with pyinstaller and it works fine. You need to provide more details about exactly how and where you are running this program.

1 solution

Probably, it has to do with the EXE file location: if it's properly installed, it will be under "Program Files" (or "Program Files (x86)" for 32 bit apps) and these folders are write protected to prevent (or at least reduce) malware activity.

So start by checking the folder for the EXE file and the SqLite DB file and move it if necessary to a more sensible place.
This may help: Where should I store my data?[^] - the code is C#, but the Python equivalent uses os.getenv[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900