I'm making a Worker Management app for a local vendor. The textvariables i have declared are not working properly. Instead of getting the inputted idNumber I'm always getting 0 on the console.(in savedata function) How to get data from my textvariable?
from tkinter import *
root = Tk()
Declared the variables here
idNumber = IntVar()
Name = StringVar()
FName = StringVar()
Address = StringVar()
Mobile = StringVar()
IDCard = StringVar()
DOJ = StringVar()
Skill = StringVar()
Wage = StringVar()
OT = StringVar()
Main Gui Window
class mainWindow:
def __init__(self):
pass
def MainWindow(self, mainW):
mainW.config(background='black')
Label(mainW, text='Welcome to Worker Management App...', font=('Comic Sans MS', 32, 'bold'), fg='white',
bg='black').grid(row=1, column=1)
Label(mainW, text='Choose a category:', font=('Comic Sans MS', 32, 'bold'), fg='white', bg='black').grid(row=2,
column=1)
Label(mainW, bg='black').grid(row=3, column=1)
Label(mainW, bg='black').grid(row=4, column=1)
Button(mainW, text='1. Individual', font=('Comic Sans MS', 28), fg='white', bg='black', command=guiIndi).grid(
row=5, column=1)
Label(mainW, bg='black').grid(row=6, column=1)
Label(mainW, bg='black').grid(row=7, column=1)
b2 = Button(mainW, text='2. Contractor', font=('Comic Sans MS', 28), fg='white', bg='black')
b2.grid(row=8, column=1)
Label(mainW, bg='black').grid(row=9, column=1)
def guiIndi():
B1 = Button(root, text='Register New', font=('Comic Sans MS', 20), fg='white', bg='black')
B1.place(x=100, y=285)
indi = Individual()
B1.config(command=indi.IndiGui)
B2 = Button(root, text='Existing', font=('Comic Sans MS', 20), fg='white', bg='black')
B2.place(x=580, y=285)
Label(root, bg='black', fg='white').grid(row=7)
Label(root, bg='black', fg='white').grid(row=8)
Label(root, bg='black', fg='white').grid(row=9)
Label(root, bg='black', fg='white').grid(row=10)
The function I'm trying to access data
def savedata(idNumber, Name, FName, Address, Mobile, IDCard,DOJ, Skill, Wage, OT):
print(idNumber.get())
The class where Data is to be entered:
class Individual():
def __init__(self):
pass
def IndiGui(self):
b = Tk()
b.config(background='black')
# cursor.execute('''
# CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT,fname TEXT,
# address TEXT, mobile TEXT,idcard TEXT ,
# doj TEXT, skill TEXT, wage TEXT, ot TEXT)
# ''')
# db.commit()
Label(b, fg='white', bg='black').grid(row=0)
l1 = Label(b, text='ID Number: ', fg='white', bg='black')
l1.grid(row=1, column=0, sticky=W, padx=15)
e1 = Entry(b, textvariable=idNumber)
e1.grid(row=1, column=1, sticky=W, padx=15)
Label(b, fg='white', bg='black').grid(row=2)
l2 = Label(b, text='Name: ', fg='white', bg='black')
l2.grid(row=3, column=0, sticky=W, padx=15)
e2 = Entry(b, textvariable=Name)
e2.grid(row=3, column=1, sticky=W, padx=15)
Label(b, fg='white', bg='black').grid(row=4)
l3 = Label(b, text="Father's Name: ", fg='white', bg='black')
l3.grid(row=5, column=0, sticky=W, padx=15)
e3 = Entry(b, textvariable=FName)
e3.grid(row=5, column=1, sticky=W, padx=15)
Label(b, fg='white', bg='black').grid(row=6)
l4 = Label(b, text='Address: ', fg='white', bg='black')
l4.grid(row=7, column=0, sticky=W, padx=15)
e4 = Entry(b, textvariable=Address)
e4.grid(row=7, column=1, sticky=W, padx=15)
Label(b, fg='white', bg='black').grid(row=8)
l5 = Label(b, text='Mobie Number ', fg='white', bg='black')
l5.grid(row=9, column=0, sticky=W, padx=15)
e5 = Entry(b, textvariable=Mobile)
e5.grid(row=9, column=1, sticky=W, padx=15)
Label(b, fg='white', bg='black').grid(row=10)
l6 = Label(b, text='ID Card Number: ', fg='white', bg='black')
l6.grid(row=11, column=0, sticky=W, padx=15)
e6 = Entry(b, textvariable=IDCard)
e6.grid(row=11, column=1, sticky=W, padx=15)
Label(b, fg='white', bg='black').grid(row=12)
l7 = Label(b, text='Date of Joining: ', fg='white', bg='black')
l7.grid(row=13, column=0, sticky=W, padx=15)
e7 = Entry(b, textvariable=DOJ)
e7.grid(row=13, column=1, sticky=W, padx=15)
Label(b, fg='white', bg='black').grid(row=14)
l8 = Label(b, text='Skill: ', fg='white', bg='black')
l8.grid(row=15, column=0, sticky=W, padx=15)
e8 = Entry(b, textvariable=Skill)
e8.grid(row=15, column=1, sticky=W, padx=15)
Label(b, fg='white', bg='black').grid(row=16)
l9 = Label(b, text='Wages: ', fg='white', bg='black')
l9.grid(row=17, column=0, sticky=W, padx=15)
e9 = Entry(b, textvariable=Wage)
e9.grid(row=17, column=1, sticky=W, padx=15)
Label(b, fg='white', bg='black').grid(row=18)
l9 = Label(b, text='Over Time: ', fg='white', bg='black')
l9.grid(row=19, column=0, sticky=W, padx=15)
e9 = Entry(b, textvariable=OT)
e9.grid(row=19, column=1, sticky=W, padx=15)
Label(b, fg='white', bg='black').grid(row=20)
b1 = Button(b, text='Go', fg='white', bg='black', font=(14))
b1.grid(row=21, column=0, columnspan=2)
b1.config(command=lambda:
savedata(idNumber,Name,FName,Address,Mobile,IDCard,DOJ,Skill,Wage,OT))
Label(b, fg='white', bg='black').grid(row=22)
b.mainloop()
app = mainWindow()
app.MainWindow(root)
root.mainloop()