I am a beginner in coding, was making a GUI in python on student registration with database. While running the code, though the code was running succesfully, there was a problem in output as neither the attributes were not showing as Name,DOB etc. Neither the heading of Student and parent details were showing. I hope someone might help me out here. I have given the code below. The GUI is still pending so the code is not complete.
from tkinter import *
from datetime import date
from tkinter import filedialog
from tkinter import messagebox
import variable as variable
from PIL import Image, ImageTk
import os
from tkinter.ttk import Combobox
import openpyxl, xlrd
from openpyxl import Workbook
import pathlib
#gender
def selection():
value = radio.get()
if value == 1:
gender= "Male"
else:
gender="Female"
#######Exit window
def Exit():
root.destroy()
########Show Image##########
def showimage():
global filename
global img
filename = filedialog.askopenfilename(initialdir=os.getcwd(),
title="Select image file",
filetype=(("JPG File","*.jpg"),
("PNG File","*.png"),
("All files","*.txt")))
img = (Image.open(filename))
resized_image = img.resize((200,200))
photo2 = ImageTk.PhotoImage(resized_image)
lb1.config(image=photo2)
lb1.image = photo2
#### Registration No. ######
#It is created to automatic enter registration no.
def registration_no():
pass
background = '#06283D'
framebg = '#EDEDED'
framefg = '#06283D'
root = Tk()
root.title('Student Registration System')
root.geometry('1250x700+130+50')
root.config(bg=background)
file = pathlib.Path('Student_data.xlsx')
if file.exists():
pass
else:
file = Workbook()
sheet = file.active
sheet['A1'] = "Registration No. "
sheet['B1'] = "Name"
sheet['C1'] = "Class"
sheet['D1'] = "Gender"
sheet['E1'] = "DOB"
sheet['F1'] = "Date Of Registration"
sheet['G1'] = "Religion"
sheet['H1'] = "Skill"
sheet['I1'] = "Father Name"
sheet['J1'] = "Mothers Name"
sheet['K1'] = "Fathers's Occupation"
sheet['L1'] = "Mothers's Occupation"
file.save('Student_data.xlsx')
# top frame
Label(root, text='Email: rishikajain@gmail.com', width=10, height=3, bg='#f0687c', anchor='e').pack(side=TOP, fill=X)
Label(root, text='Student Registration', width=10, height=2, bg='#c36464', fg="#fff", font='arial 20 bold').pack(
side=TOP, fill=X)
# search box to update
search_var = StringVar()
search_var = Entry(root, textvariable=search_var, width=15, bd=3, font="arial 20").place(x=820, y=70)
search_image = Image.open("search_icon.jpg")
# search_image = search_image.resize((10, 10), Image.ANTIALIAS)
search_image = search_image.resize((10, 10), resample= Image.LANCZOS)
imageicon3 = ImageTk.PhotoImage(search_image)
search_button = Button(root, text="Search", compound=LEFT, image=imageicon3, width=70, height=60, bg='#68ddfa',`your text`font="arial 13 bold")
search_button.place(x=1070, y=52)
# imageicon4 = ImageTk.PhotoImage(file="Layer 4.jpg")
# Update_button = Button(root,image = imageicon4,bg= '#c36464')
Update = Image.open("Layer 4.jpg")
# Update_resize = Update.resize((50, 50), Image.ANTIALIAS)
Update_resize = Update.resize((50, 50), resample=Image.LANCZOS)
imageicon4 = ImageTk.PhotoImage(Update_resize)
imageicon4 = Button(root, image=imageicon4)
imageicon4.place(x=100, y=60)
# Registration and Date
Label(root, text="Registration No: ", font='arial 13', fg=framebg, bg=background).place(x=30, y=150)
Label(root, text="Date: ", font='arial 13', fg=framebg, bg=background).place(x=500, y=150)
Registration = StringVar()
Date = StringVar()
reg_entry = Entry(root, textvariable=Registration, width=15, font="arial 10")
reg_entry.place(x=160, y=150)
registration_no()
today = date.today()
d1 = today.strftime("%d/%m/%Y")
date_entry = Entry(root, textvariable= Date, width=15, font="arial 10")
date_entry.place(x=550, y=150)
Date.set(d1)
# student details
obj = LabelFrame(root, text="Student's Details", font=20, bd=2, width=900, bg=framebg, fg=framebg, height=250,
relief=GROOVE)
obj.place(x=30, y=200)
Label(obj, text="Full Name: ", font="arial 13", bg=framebg, fg=framebg).place(x=30, y=50)
Label(obj, text="Date of Birth: ", font="arial 13", bg=framebg, fg=framebg).place(x=30, y=100)
Label(obj, text="Gender: ", font="arial 13", bg=framebg, fg=framebg).place(x=30, y=150)
Label(obj, text="Class : ", font="arial 13", bg=framebg, fg=framebg).place(x=500, y=50)
Label(obj, text="Religion : ", font="arial 13", bg=framebg, fg=framebg).place(x=500, y=100)
Label(obj, text="Skills : ", font="arial 13", bg=framebg, fg=framebg).place(x=500, y=150)
Name = StringVar()
name_entry = Entry(obj,textvariable= Name, width = 20, font = "arial 10")
name_entry.place(x= 160,y=50)
DOB = StringVar()
dob_entry = Entry(obj,textvariable= DOB, width = 20, font = "arial 10")
dob_entry.place(x= 160,y=100)
radio = IntVar()
R1 = Radiobutton(obj,text= "Male", variable = radio, value= 1, bg= framebg, fg= framebg, command= selection)
R1.place(x= 150, y=150)
R2 = Radiobutton(obj,text = "Female", variable = radio, value=2, bg=framebg, fg= framebg, command=selection)
R2.place(x=200, y=150)
Religion = StringVar()
religion_entry = Entry(obj,textvariable= Religion, width = 20, font = "arial 10")
dob_entry.place(x= 630,y=100)
Skill = StringVar()
skill_entry = Entry(obj,textvariable= Skill, width = 20, font = "arial 10")
skill_entry.place(x= 630,y=150)
Class = Combobox(obj, values= ['1','2','3','4','5','6','7','8','9','10'],font='Roboto 10',width=17, state= 'r')
Class.place(x=630,y=50)
Class.set("Select Class")
# Parents details
obj2 = LabelFrame(root, text="Parent's Details", font=20, bd=2, width=900, bg=framebg, fg=framebg, height=220, relief=GROOVE)
obj2.place(x=30, y=470)
Label(obj2,text= "Fathers Name: ",font= "arial 13",bg=framebg,fg=framebg).place(x=30,y=50)
Label(obj2,text= "Occupation: ",font= "arial 13",bg=framebg,fg=framebg).place(x=30,y=50)
F_Name = StringVar()
f_entry = Entry(obj2,textvariable= Name, width = 20, font = "arial 10")
f_entry.place(x= 160,y=50)
Father_Occupation = StringVar()
FO_entry = Entry(obj2,textvariable= Name, width = 20, font = "arial 10")
FO_entry.place(x= 160,y=100)
Label(obj2,text= "Mothers Name: ",font= "arial 13",bg=framebg,fg=framebg).place(x=500,y=50)
Label(obj2,text= "Occupation: ",font= "arial 13",bg=framebg,fg=framebg).place(x=500,y=100)
M_Name = StringVar()
M_entry = Entry(obj2,textvariable= Name, width = 20, font = "arial 10")
M_entry.place(x= 630,y=50)
Mother_Occupation = StringVar()
MO_entry = Entry(obj2,textvariable= Name, width = 20, font = "arial 10")
MO_entry.place(x= 630,y=100)
#image
f =Frame(root,bd=3,bg="black",width=200,height= 200,relief=GROOVE)
f.place(x=1000,y=150)
img = PhotoImage(file="userprofile.png")
lb1 =Label(f,bg="black",image=img)
lb1.place(x=0,y=0)
#button
Button(root,text="Upload",width=19,height=2,font="arial 12 bold",bg="lightblue",command=showimage).place(x=1000,y=370)
saveButton = Button(root,text="Save",width=19,height=2,font="arial 12 bold",bg="lightgreen").place(x=1000,y=450)
Button(root,text="Reset",width=19,height=2,font="arial 12 bold",bg="lightpink").place(x=1000,y=530)
Button(root,text="Exit",width=19,height=2,font="arial 12 bold",bg="grey",command=Exit).place(x=1000,y=610)
root.mainloop()
Till now only upload and exit are working and complete database is left. I hope someone may help me telling where i have made mistake.
search_var
here: you set it as aStringVar
, which is fine, but then you immediately overwrite it with theEntry
declaration which is evaluating toNone
because you've chained thatEntry
toplace
(which returnsNone
). If you need to refer to thisEntry
widget anywhere else, give it a different variable name and callthat_name.place(...)
on a separate line like you've done with yourdob_entry
andRadiobutton
s