Reputation: 25
Its Not Giving Any Errors Just Not Showing Up If it seems a little choppy sorry been getting frustrated but literally everything works no errors at all it even enters the camper id but no name someone please help, thank you, and dont down this please been getting allot of strikes even though most of the people dont actually read the code [FIXED]
import tkinter
from tkinter import *
import random
from random import randint
import sqlite3
from sqlite3 import *
#creating screen
page = tkinter.Tk()
#naming screen
page.title('Camp Sign-up')
#setting screen size
page.geometry("1000x500")
#creating text
Title = tkinter.Label(page, text='Registration', font=('arial') ).pack()
FullName = tkinter.Label(page, text='Full Name:', font=('arial')).place(x=110, y=50)
full = StringVar()
FullNameValue = Entry(page, textvar=full, width=25,).place(x=200, y=53)
CamperID = random.randint(100000, 1000000)
#Database
conn = sqlite3.connect('YouthCamp.db')
c = conn.cursor()
def createtable():
c.execute("""CREATE TABLE Registration (
CampID INT,
full TEXT,
)""")
try:
createtable()
except:
sqlite3.OperationalError
#button
def buttonclick():
#heres where you lnk where you want your info to go
FullNameValu= full.get()
conn = sqlite3.connect('YouthCamp.db')
c = conn.cursor()
c.execute("INSERT INTO Registration(CampID, full)VALUES(?, ?)",(CamperID, FullNameValu))
conn.commit()
#button
work = Button(page, text='Submit', width=10, height=2, bg='lightgrey',
command=buttonclick()).place(x=475, y=450)
#heres where you execute your close files commands
conn.commit()
c.close()
conn.close()
#ending code never put this above anything
page.mainloop()
Upvotes: 0
Views: 56
Reputation: 1474
Your buttonclick()
run as soon as you start the program cause have done this way command=buttonclick()
which suppose to be command=buttonclick
. Also your creation of your database is not good have changed that and refactor your all code.
import tkinter
from tkinter import *
import random
from random import randint
import sqlite3
from sqlite3 import *
# THIS IS CREATING DATABASE
conn = sqlite3.connect('YouthCamp.db')
c = conn.cursor()
c.execute("""CREATE TABLE IF NOT EXISTS Registration (CampID INT, full TEXT)""")
conn.commit()
conn.close()
#button
def buttonclick():
#heres where you lnk where you want your info to go
FullNameValu= full.get()
# generating the camp id
CamperID = random.randint(100000, 1000000)
conn = sqlite3.connect('YouthCamp.db')
c = conn.cursor()
c.execute("INSERT INTO Registration(CampID, full)VALUES(?, ?)",(CamperID, FullNameValu))
conn.commit()
conn.close()
print("records inserted")
#creating screen
page = tkinter.Tk()
#naming screen
page.title('Camp Sign-up')
#setting screen size
page.geometry("1000x500")
#creating text
Title = tkinter.Label(page, text='Registration', font=('arial') )
Title.pack()
FullName = tkinter.Label(page, text='Full Name:', font=('arial'))
FullName.place(x=110, y=50)
full = StringVar()
FullNameValue = Entry(page, textvar=full, width=25,)
FullNameValue.place(x=200, y=53)
#button
work = Button(page, text='Submit', width=10, height=2, bg='lightgrey',
command=buttonclick).place(x=475, y=450)
page.mainloop()
Upvotes: 1