CODE::
JavaScript
x
64
64
1
from tkinter import *
2
import tkinter.messagebox
3
4
5
class Library:
6
7
def __init_(self, root):
8
self.root = root
9
self.root.title(" Library Management System ")
10
self.root.geometry("1350x750+0+0")
11
12
MTy = StringVar()
13
Ref = StringVar()
14
Title = StringVar()
15
fna = StringVar()
16
sna = StringVar()
17
Adr1 = StringVar()
18
Adr2 = StringVar()
19
pcd = StringVar()
20
MNo = StringVar()
21
BkID = StringVar()
22
Bkt = StringVar()
23
BkT = StringVar()
24
Atr = StringVar()
25
DBo = StringVar()
26
Ddu = StringVar()
27
sPr = StringVar()
28
Lrf = StringVar()
29
Dod = StringVar()
30
DonL = StringVar()
31
32
#============================================FRAMES=================================================#
33
34
MainFrame = Frame(self.root)
35
MainFrame.grid()
36
37
Title_Frame = Frame(MainFrame, bd=2, padx=40, pady=8, bg='cadet blue', relief=RIDGE)
38
Title_Frame.grid(side=TOP)
39
40
self.lblTitle = Label(Title_Frame, font=('arial', 46, 'bold'), text=" Library Management System ")
41
self.lblTitle.grid(sticky=W)
42
43
ButtonFrame = Frame(MainFrame, bd=2, width=1350, height=100, padx=20, pady=20, bg='Cadet Blue', relief=RIDGE)
44
ButtonFrame.pack(side=BOTTOM)
45
46
FrameDetail = Frame(MainFrame, bd=0, width=1350, height=50, padx=20, relief=RIDGE)
47
FrameDetail.pack(side=BOTTOM)
48
49
DataFrame = Frame(MainFrame, bd=1, width=1300, height=400, padx=20, pady=20, relief=RIDGE)
50
DataFrame.pack(side=BOTTOM)
51
52
DataFrameLEFT = LabelFrame(DataFrame, bd=1, width=800, height=300, padx=20, relief=RIDGE,
53
font=('arial', 12, 'bold'), text=' Library Member Info ', bg='Cadet Blue')
54
DataFrameLEFT.pack(side=LEFT)
55
56
DataFrameRIGHT = LabelFrame(DataFrame, bd=1, width=450, height=300, padx=20, pady=3, relief=RIDGE,
57
font=('arial', 12, 'bold'), text=' Book Details ', bg='Cadet Blue')
58
DataFrameRIGHT.pack(side=RIGHT)
59
60
if __name__ == '__main__':
61
root = Tk()
62
application = Library(root)
63
root.mainloop()
64
Error::
Traceback (most recent call last): File “C:/Users/Jedi/PycharmProjects/LMS/main.py”, line 5, in class Library: File “C:/Users/Jedi/PycharmProjects/LMS/main.py”, line 62, in Library application = Library(root) NameError: name ‘Library’ is not defined
Process finished with exit code 1
Advertisement
Answer
Firstly, your indentation is wrong, you have to place the if
on the same indentation level as class
, like:
JavaScript
1
6
1
class Library:
2
..
3
4
if __name__ == '__main__':
5
.
6
Secondly, but most importantly, your def __init_()
has a typo, it should be __init__()
with two underscore trailing and leading init, but you gave just one(trailing).
JavaScript
1
5
1
class Library:
2
def __init__(self, root):
3
self.root = root
4
..
5
But even after doing all this, you will get another error at Title_Frame.grid(side=TOP)
, because grid()
has not option side
, it is the option of pack()
, so change that to:
JavaScript
1
2
1
Title_Frame.pack(side=TOP)
2