import tkinter
import tkinter.messagebox
import tkinter.ttk
classes
={'1':
['z1',
'z2',
'z3',
'z4'],
'2':
['l1',
'l2',
'l3'],
'3':
['m5',
'm6',
'm7',
'm8']}
root
=tkinter.Tk
()
root.title
("GUI TWO")
root
['height']=300
root
['width']=270
def changeClass
(event
):
grade
=comboGrade.get
()
if grade:
comboClass
['values']=classes.get
(grade
)
else:
comboClass
['values']=[]
def add
():
name
=entryName.get
()
grade
=comboGrade.get
()
cla
=comboClass.get
()
if not
(name.strip
() and grade and cla
):
tkinter.messagebox.showerror
('Add denied',
'information is not completed!')
mess
=name+
";"+grade+
";"+cla+
";"+
('Man' if sex.get
() else 'Woman')+
";"+
('Y' if varLeader.get
() else 'N')
listboxData.insert
(0,mess
)
print
(mess.split
(";"))
def deleteItem
():
currentItem
=listboxData.curselection
()
if currentItem:
listboxData.delete
(currentItem
)
else:
tkinter.messagebox.showinfo
(title
="Delete denied", message
="selected item is null!")
labelName
=tkinter.Label
(root,
text
='Name:',
justify
=tkinter.RIGHT,
width
=50
)
labelName.place
(x
=10,y
=5,width
=50,height
=20
)
varName
=tkinter.StringVar
(root,value
='')
entryName
=tkinter.Entry
(root,
width
=80,
textvariable
=varName
)
entryName.place
(x
=70,y
=5,width
=150,height
=20
)
labelGrade
=tkinter.Label
(root,
text
='Grade:',
justify
=tkinter.RIGHT,
width
=50
)
labelGrade.place
(x
=10,y
=40,width
=50,height
=20
)
comboGrade
=tkinter.ttk.Combobox
(root,
width
=50,
values
=tuple
(classes.keys
()))
comboGrade.place
(x
=70,y
=40,width
=50,height
=20
)
labelClass
=tkinter.Label
(root,
text
='Class:',
justify
=tkinter.RIGHT,
width
=50
)
labelClass.place
(x
=150,y
=40,width
=50,height
=20
)
comboClass
=tkinter.ttk.Combobox
(root,width
=50
)
comboClass.place
(x
=200,y
=40,width
=50,height
=20
)
labelSex
=tkinter.Label
(root,
text
='Sex:',
justify
=tkinter.RIGHT,
width
=50
)
labelSex.place
(x
=5,y
=70,width
=50,height
=20
)
sex
=tkinter.IntVar
(root,value
=1
)
radioMan
=tkinter.Radiobutton
(root,
text
='Man',
value
=1,
variable
=sex
)
radioMan.place
(x
=70,y
=70,width
=50,height
=20
)
radioWoman
=tkinter.Radiobutton
(root,
text
='Woman',
value
=0,
variable
=sex
)
radioWoman.place
(x
=140,y
=70,width
=90,height
=20
)
varLeader
=tkinter.IntVar
(root,value
=0
)
checkLeader
=tkinter.Checkbutton
(root,
text
='is leader?',
variable
=varLeader,
onvalue
=1,
offvalue
=0
)
checkLeader.place
(x
=10,y
=100,width
=90,height
=20
)
buttonAdd
=tkinter.Button
(root,
text
='Add',
width
=40,
command
=add
)
buttonAdd.place
(x
=150,y
=100,width
=40,height
=20
)
buttonDelete
=tkinter.Button
(root,
text
='Delete',
width
=80,
command
=deleteItem
)
buttonDelete.place
(x
=200,y
=100,width
=50,height
=20
)
listboxData
=tkinter.Listbox
(root,width
=300
)
listboxData.place
(x
=15,y
=130,width
=235,height
=150
)
comboGrade.bind
('<<ComboboxSelected>>',changeClass
)
root.mainloop
()