Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Tkinter
- import tkMessageBox
- #windowbox
- WindowBox = Tkinter.Tk()
- WindowBox.geometry("250x200")
- WindowBox.title("Welcome to E-UPSR")
- Tkinter.Label (WindowBox, text="Username:").pack()
- username1 = Tkinter.Entry (WindowBox)
- username1.pack()
- Tkinter.Label (WindowBox, text="Password:").pack()
- password1 = Tkinter.Entry (WindowBox)
- password1.pack()
- student=[]
- #read back student text file(proceed button)
- def read():
- if not username1.get() or not password1.get():
- tkMessageBox.showerror('Invalid', 'Empty username or password')
- else:
- addstudent = open ("student.txt", "r")
- lines = addstudent.readlines()
- addstudent.close ()
- i = 0
- while i < len(lines) - 1:
- # username and password are saved in two line, label and value are separated by ':'.
- # to get them we need to reed two line in each iteration and split with ':' to get the value (second result of spliting) then strip to remove end line.
- user = lines[i].split(':')[1].strip()
- password = lines[i+1].split(':')[1].strip()
- # test if the user is registred
- if user == username1.get() and password == password1.get():
- WindowBox.withdraw()
- MenuBox.deiconify()
- break
- i += 2
- return
- #register button
- def register():
- WindowBox.withdraw()
- RegBox.deiconify()
- return
- #registerbox
- RegBox = Tkinter.Tk()
- RegBox.geometry("250x200")
- RegBox.title("register")
- Tkinter.Label (RegBox, text="Username:").pack()
- username2 = Tkinter.Entry (RegBox)
- username2.pack()
- Tkinter.Label (RegBox, text="Password:").pack()
- password2 = Tkinter.Entry (RegBox)
- password2.pack()
- RegBox.withdraw()
- #back button in registerbox
- def back():
- RegBox.withdraw()
- WindowBox.deiconify()
- return
- #register save in student.text file
- def save():
- if not username2.get() or not password2.get():
- tkMessageBox.showerror('Invalid', 'Empty username or password')
- else:
- addstudent = open ("student.txt", "a")
- addstudent.write('Username:' + username2.get() + 'n')
- addstudent.write('Password:' + password2.get()+'n')
- tkMessageBox.showinfo("Writing", "Done")
- return
- MenuBox = Tkinter.Tk()
- MenuBox.geometry("250x200")
- MenuBox.title("MainMenu")
- MenuBox.withdraw()
- #Math easay difficulty
- #Q1
- EasyBox1 = Tkinter.Tk()
- EasyBox1.geometry("250x200")
- EasyBox1.title("Quesion 1")
- Tkinter.Label (EasyBox1, text="answer:").pack()
- answr1 = Tkinter.Entry (EasyBox1)
- answr1.pack()
- LabelName2 = Tkinter.Label (EasyBox1, text="State the number of edges in a cube")
- LabelName2.grid(row=1,column=0)
- LabelName2.pack()
- def next1():
- total = 0
- if not answr1.get():
- tkMessageBox.showerror('no answer')
- elif answr1.get() == 8 :
- total = total + 1
- EasyBox1.withdraw()
- EasyBox2.deiconify()
- elif answr1.get() != 8:
- total = total
- EasyBox1.withdraw()
- EasyBox2.deiconify()
- return
- EasyBox1.withdraw()
- #Q2
- EasyBox2 = Tkinter.Tk()
- EasyBox2.geometry("250x200")
- EasyBox2.title("Quesion 2")
- Tkinter.Label (EasyBox2, text="answer:").pack()
- answr2 = Tkinter.Entry (EasyBox2)
- answr2.pack()
- LabelName2 = Tkinter.Label (EasyBox2, text="What is the place value of the digit 4 in 76421?")
- LabelName2.grid(row=1,column=0)
- LabelName2.pack()
- LabelName2 = Tkinter.Label (EasyBox2, text="A.Thousands B.Hundreds C.Ones D.Tens")
- LabelName2.grid(row=1,column=0)
- LabelName2.pack()
- def mark():
- total = 0
- if not answr2.get():
- tkMessageBox.showerror('no answer')
- elif answr2.get() in ["B", "b"]:
- total = total + 1
- EasyBox2.withdraw()
- ResultBox.deiconify()
- else:
- total = total
- EasyBox2.withdraw()
- ResultBox.deiconify()
- return
- EasyBox2.withdraw()
- total = 0
- ResultBox = Tkinter.Tk()
- ResultBox.geometry("320x260")
- ResultBox.title("Results")
- LabelName5 = Tkinter.Label (ResultBox, text="Marks : "+`total`, font=("Impact",20))
- LabelName5.grid(row=2,column=0)
- ResultBox.withdraw()
- def menu():
- ResultBox.withdraw()
- MenuBox.deiconify()
- return
- Tkinter.Button (EasyBox1, text="Next", command=next1).pack()
- Tkinter.Button (EasyBox2, text="result", command=mark).pack()
- Tkinter.Button (ResultBox, text="Main Menu",command=menu,width=15).place(relx=.3,rely=.7)
- #Math moderate
- ModerateBox1 = Tkinter.Tk()
- ModerateBox1.geometry("250x200")
- ModerateBox1.title("Math Moderate")
- ModerateBox1.withdraw()
- HardBox1 = Tkinter.Tk()
- HardBox1.geometry("250x200")
- HardBox1.title("Math Hard")
- HardBox1.withdraw()
- #Bm difficulty
- EasyBox2_bm = Tkinter.Tk()
- EasyBox2_bm.geometry("250x200")
- EasyBox2_bm.title("Bm Easy")
- EasyBox2_bm.withdraw()
- ModerateBox2_bm = Tkinter.Tk()
- ModerateBox2_bm.geometry("250x200")
- ModerateBox2_bm.title("Bm Moderate")
- ModerateBox2_bm.withdraw()
- HardBox2_bm = Tkinter.Tk()
- HardBox2_bm.geometry("250x200")
- HardBox2_bm.title("Bm Hard")
- HardBox2_bm.withdraw()
- #Sn difficulty
- EasyBox3 = Tkinter.Tk()
- EasyBox3.geometry("250x200")
- EasyBox3.title("Sn Easy")
- EasyBox3.withdraw()
- ModerateBox3 = Tkinter.Tk()
- ModerateBox3.geometry("250x200")
- ModerateBox3.title("Sn Moderate")
- ModerateBox3.withdraw()
- HardBox3 = Tkinter.Tk()
- HardBox3.geometry("250x200")
- HardBox3.title("Sn Hard")
- HardBox3.withdraw()
- #Eng difficulty
- EasyBox4 = Tkinter.Tk()
- EasyBox4.geometry("250x200")
- EasyBox4.title("Eng Easy")
- EasyBox4.withdraw()
- ModerateBox4 = Tkinter.Tk()
- ModerateBox4.geometry("250x200")
- ModerateBox4.title("Eng Moderate")
- ModerateBox4.withdraw()
- HardBox4 = Tkinter.Tk()
- HardBox4.geometry("250x200")
- HardBox4.title("Eng Hard")
- HardBox4.withdraw()
- def Math():
- MenuBox.withdraw()
- MathBox.deiconify()
- return
- def Bm():
- MenuBox.withdraw()
- BmBox.deiconify()
- return
- def Sn():
- MenuBox.withdraw()
- SnBox.deiconify()
- return
- def Eng():
- MenuBox.withdraw()
- EngBox.deiconify()
- return
- def back1():
- MathBox.withdraw()
- EngBox.withdraw()
- SnBox.withdraw()
- BmBox.withdraw()
- MenuBox.deiconify()
- return
- #def startbutton in MathBox
- def start1():
- if not var.get():
- tkMessageBox.showerror('Choose One')
- elif var.get()== 1:
- MathBox.withdraw()
- EasyBox1.deiconify()
- tkMessageBox.showinfo('Goodluck')
- elif var.get()==2:
- MathBox.withdraw()
- ModerateBox1.deiconify()
- tkMessageBox.showinfo('Goodluck')
- else:
- MathBox.withdraw()
- HardBox1.deiconify()
- tkMessageBox.showinfo('Goodluck')
- return
- #radiobutton for MathBox
- from Tkinter import *
- def sel1(number):
- var.set(number)
- selection = "You selected the option " + str(var.get())
- label.config(text = selection)
- MathBox = Tk()
- MathBox.geometry("250x200")
- MathBox.title("Math")
- var = IntVar()
- R1 = Radiobutton(MathBox, text="Easy", variable=var, value=1,
- command=lambda: sel1(1))
- R1.pack( anchor = W)
- R2 = Radiobutton(MathBox, text="Moderate", variable=var, value=2,
- command=lambda: sel1(2))
- R2.pack( anchor = W )
- R3 = Radiobutton(MathBox, text="Hard", variable=var, value=3,
- command=lambda: sel1(3))
- R3.pack( anchor = W)
- label = Label(MathBox)
- label.pack()
- MathBox.withdraw()
- #def startbutton in BmBox
- def start2():
- if not var.get():
- tkMessageBox.showerror('Choose One')
- elif var.get()== 1:
- BmBox.withdraw()
- EasyBox2.deiconify()
- tkMessageBox.showinfo('Goodluck')
- elif var.get()==2:
- BmBox.withdraw()
- ModerateBox2.deiconify()
- tkMessageBox.showinfo('Goodluck')
- else:
- BmBox.withdraw()
- HardBox2.deiconify()
- tkMessageBox.showinfo('Goodluck')
- return
- #radionbutton for BM
- from Tkinter import *
- def sel2(number):
- var.set(number)
- selection = "You selected the option " + str(var.get())
- label.config(text = selection)
- BmBox = Tk()
- BmBox.geometry("250x200")
- BmBox.title("Bm")
- var = IntVar()
- R1 = Radiobutton(BmBox, text="Easy", variable=var, value=1,
- command=lambda: sel2(1))
- R1.pack( anchor = W)
- R2 = Radiobutton(BmBox, text="Moderate", variable=var, value=2,
- command=lambda: sel2(2))
- R2.pack( anchor = W )
- R3 = Radiobutton(BmBox, text="Hard", variable=var, value=3,
- command=lambda: sel2(3))
- R3.pack( anchor = W)
- label = Label(BmBox)
- label.pack()
- BmBox.withdraw()
- #def startbutton in SnBox
- def start3():
- if not var.get():
- tkMessageBox.showerror('Choose One')
- elif var.get()== 1:
- SnBox.withdraw()
- EasyBox3.deiconify()
- tkMessageBox.showinfo('Goodluck')
- elif var.get()==2:
- SnBox.withdraw()
- ModerateBox3.deiconify()
- tkMessageBox.showinfo('Goodluck')
- else:
- SnBox.withdraw()
- HardBox3.deiconify()
- tkMessageBox.showinfo('Goodluck')
- return
- #radionbutton for Sn
- from Tkinter import *
- def sel(number):
- var.set(number)
- selection = "You selected the option " + str(var.get())
- label.config(text = selection)
- SnBox = Tk()
- SnBox.geometry("250x200")
- SnBox.title("Science")
- var = IntVar()
- R1 = Radiobutton(SnBox, text="Easy", variable=var, value=1,
- command=lambda: sel(1))
- R1.pack( anchor = W)
- R2 = Radiobutton(SnBox, text="Moderate", variable=var, value=2,
- command=lambda: sel(2))
- R2.pack( anchor = W )
- R3 = Radiobutton(SnBox, text="Hard", variable=var, value=3,
- command=lambda: sel(3))
- R3.pack( anchor = W)
- label = Label(SnBox)
- label.pack()
- SnBox.withdraw()
- #def startbutton in EngBox
- def start4():
- if not var.get():
- tkMessageBox.showerror('Choose One')
- elif var.get()== 1:
- EngBox.withdraw()
- EasyBox4.deiconify()
- tkMessageBox.showinfo('Goodluck')
- elif var.get()==2:
- EngBox.withdraw()
- ModerateBox4.deiconify()
- tkMessageBox.showinfo('Goodluck')
- else:
- EngBox.withdraw()
- HardBox4.deiconify()
- tkMessageBox.showinfo('Goodluck')
- return
- #radiobutton for eng
- from Tkinter import *
- def sel(number):
- var.set(number)
- selection = "You selected the option " + str(var.get())
- label.config(text = selection)
- EngBox = Tk()
- EngBox.geometry("250x200")
- EngBox.title("English")
- var = IntVar()
- R1 = Radiobutton(EngBox, text="Easy", variable=var, value=1,
- command=lambda: sel(1))
- R1.pack( anchor = W)
- R2 = Radiobutton(EngBox, text="Moderate", variable=var, value=2,
- command=lambda: sel(2))
- R2.pack( anchor = W )
- R3 = Radiobutton(EngBox, text="Hard", variable=var, value=3,
- command=lambda: sel(3))
- R3.pack( anchor = W)
- label = Label(EngBox)
- label.pack()
- EngBox.withdraw()
- #All button
- Tkinter.Button (RegBox, text="Back", command=back).pack()
- Tkinter.Button (RegBox, text="Enter", command=save).pack()
- Tkinter.Button (WindowBox, text="Register", command=register).pack()
- Tkinter.Button (WindowBox, text="Proceed", command=read).pack()
- Tkinter.Button (MenuBox, text="Math",command=Math,width=15).place(relx=.0,rely=.2)
- Tkinter.Button (MenuBox, text="Bm",command=Bm,width=15).place(relx=.0,rely=.4)
- Tkinter.Button (MenuBox, text="Science",command=Sn,width=15).place(relx=.5, rely=.2)
- Tkinter.Button (MenuBox, text="Eng",command=Eng,width=15).place(relx=.5,rely=.4)
- Tkinter.Button (MathBox, text="Back", command=back1).place(relx=.4,rely=.7)
- Tkinter.Button (EngBox, text="Back", command=back1).place(relx=.4,rely=.7)
- Tkinter.Button (BmBox, text="Back", command=back1).place(relx=.4,rely=.7)
- Tkinter.Button (SnBox, text="Back", command=back1).place(relx=.4,rely=.7)
- Tkinter.Button (MathBox, text="Start",command=start1).pack(side=RIGHT)
- Tkinter.Button (BmBox, text="Start",command=start2).pack(side=RIGHT)
- Tkinter.Button (SnBox, text="Start",command=start3).pack(side=RIGHT)
- Tkinter.Button (EngBox, text="Start",command=start4).pack(side=RIGHT)
- WindowBox.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement