Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.59 KB | None | 0 0
  1. import Tkinter
  2. import tkMessageBox
  3.  
  4. #windowbox
  5. WindowBox = Tkinter.Tk()
  6. WindowBox.geometry("250x200")
  7. WindowBox.title("Welcome to E-UPSR")
  8.  
  9.  
  10. Tkinter.Label (WindowBox, text="Username:").pack()
  11.  
  12. username1 = Tkinter.Entry (WindowBox)
  13. username1.pack()
  14.  
  15. Tkinter.Label (WindowBox, text="Password:").pack()
  16.  
  17. password1 = Tkinter.Entry (WindowBox)
  18. password1.pack()
  19.  
  20. student=[]
  21.  
  22. #read back student text file(proceed button)
  23. def read():
  24. if not username1.get() or not password1.get():
  25. tkMessageBox.showerror('Invalid', 'Empty username or password')
  26. else:
  27. addstudent = open ("student.txt", "r")
  28. lines = addstudent.readlines()
  29. addstudent.close ()
  30. i = 0
  31. while i < len(lines) - 1:
  32. # username and password are saved in two line, label and value are separated by ':'.
  33. # 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.
  34. user = lines[i].split(':')[1].strip()
  35. password = lines[i+1].split(':')[1].strip()
  36. # test if the user is registred
  37. if user == username1.get() and password == password1.get():
  38. WindowBox.withdraw()
  39. MenuBox.deiconify()
  40. break
  41. i += 2
  42. return
  43.  
  44. #register button
  45. def register():
  46. WindowBox.withdraw()
  47. RegBox.deiconify()
  48. return
  49.  
  50. #registerbox
  51. RegBox = Tkinter.Tk()
  52. RegBox.geometry("250x200")
  53. RegBox.title("register")
  54.  
  55. Tkinter.Label (RegBox, text="Username:").pack()
  56.  
  57. username2 = Tkinter.Entry (RegBox)
  58. username2.pack()
  59.  
  60. Tkinter.Label (RegBox, text="Password:").pack()
  61.  
  62. password2 = Tkinter.Entry (RegBox)
  63. password2.pack()
  64. RegBox.withdraw()
  65.  
  66. #back button in registerbox
  67. def back():
  68. RegBox.withdraw()
  69. WindowBox.deiconify()
  70. return
  71.  
  72. #register save in student.text file
  73. def save():
  74. if not username2.get() or not password2.get():
  75. tkMessageBox.showerror('Invalid', 'Empty username or password')
  76. else:
  77. addstudent = open ("student.txt", "a")
  78. addstudent.write('Username:' + username2.get() + 'n')
  79. addstudent.write('Password:' + password2.get()+'n')
  80. tkMessageBox.showinfo("Writing", "Done")
  81. return
  82.  
  83.  
  84. MenuBox = Tkinter.Tk()
  85. MenuBox.geometry("250x200")
  86. MenuBox.title("MainMenu")
  87. MenuBox.withdraw()
  88.  
  89.  
  90.  
  91. #Math easay difficulty
  92. #Q1
  93. EasyBox1 = Tkinter.Tk()
  94. EasyBox1.geometry("250x200")
  95. EasyBox1.title("Quesion 1")
  96.  
  97. Tkinter.Label (EasyBox1, text="answer:").pack()
  98.  
  99. answr1 = Tkinter.Entry (EasyBox1)
  100. answr1.pack()
  101.  
  102. LabelName2 = Tkinter.Label (EasyBox1, text="State the number of edges in a cube")
  103. LabelName2.grid(row=1,column=0)
  104. LabelName2.pack()
  105.  
  106. def next1():
  107. total = 0
  108. if not answr1.get():
  109. tkMessageBox.showerror('no answer')
  110. elif answr1.get() == 8 :
  111. total = total + 1
  112. EasyBox1.withdraw()
  113. EasyBox2.deiconify()
  114. elif answr1.get() != 8:
  115. total = total
  116. EasyBox1.withdraw()
  117. EasyBox2.deiconify()
  118. return
  119.  
  120. EasyBox1.withdraw()
  121.  
  122. #Q2
  123. EasyBox2 = Tkinter.Tk()
  124. EasyBox2.geometry("250x200")
  125. EasyBox2.title("Quesion 2")
  126.  
  127. Tkinter.Label (EasyBox2, text="answer:").pack()
  128.  
  129. answr2 = Tkinter.Entry (EasyBox2)
  130. answr2.pack()
  131.  
  132. LabelName2 = Tkinter.Label (EasyBox2, text="What is the place value of the digit 4 in 76421?")
  133. LabelName2.grid(row=1,column=0)
  134. LabelName2.pack()
  135.  
  136. LabelName2 = Tkinter.Label (EasyBox2, text="A.Thousands B.Hundreds C.Ones D.Tens")
  137. LabelName2.grid(row=1,column=0)
  138. LabelName2.pack()
  139.  
  140. def mark():
  141. total = 0
  142. if not answr2.get():
  143. tkMessageBox.showerror('no answer')
  144. elif answr2.get() in ["B", "b"]:
  145. total = total + 1
  146. EasyBox2.withdraw()
  147. ResultBox.deiconify()
  148. else:
  149. total = total
  150. EasyBox2.withdraw()
  151. ResultBox.deiconify()
  152. return
  153.  
  154.  
  155.  
  156. EasyBox2.withdraw()
  157.  
  158.  
  159.  
  160. total = 0
  161.  
  162.  
  163. ResultBox = Tkinter.Tk()
  164. ResultBox.geometry("320x260")
  165. ResultBox.title("Results")
  166.  
  167. LabelName5 = Tkinter.Label (ResultBox, text="Marks : "+`total`, font=("Impact",20))
  168. LabelName5.grid(row=2,column=0)
  169.  
  170. ResultBox.withdraw()
  171.  
  172. def menu():
  173. ResultBox.withdraw()
  174. MenuBox.deiconify()
  175. return
  176.  
  177.  
  178. Tkinter.Button (EasyBox1, text="Next", command=next1).pack()
  179. Tkinter.Button (EasyBox2, text="result", command=mark).pack()
  180. Tkinter.Button (ResultBox, text="Main Menu",command=menu,width=15).place(relx=.3,rely=.7)
  181.  
  182.  
  183. #Math moderate
  184.  
  185. ModerateBox1 = Tkinter.Tk()
  186. ModerateBox1.geometry("250x200")
  187. ModerateBox1.title("Math Moderate")
  188. ModerateBox1.withdraw()
  189.  
  190. HardBox1 = Tkinter.Tk()
  191. HardBox1.geometry("250x200")
  192. HardBox1.title("Math Hard")
  193. HardBox1.withdraw()
  194.  
  195. #Bm difficulty
  196. EasyBox2_bm = Tkinter.Tk()
  197. EasyBox2_bm.geometry("250x200")
  198. EasyBox2_bm.title("Bm Easy")
  199. EasyBox2_bm.withdraw()
  200.  
  201. ModerateBox2_bm = Tkinter.Tk()
  202. ModerateBox2_bm.geometry("250x200")
  203. ModerateBox2_bm.title("Bm Moderate")
  204. ModerateBox2_bm.withdraw()
  205.  
  206. HardBox2_bm = Tkinter.Tk()
  207. HardBox2_bm.geometry("250x200")
  208. HardBox2_bm.title("Bm Hard")
  209. HardBox2_bm.withdraw()
  210.  
  211. #Sn difficulty
  212. EasyBox3 = Tkinter.Tk()
  213. EasyBox3.geometry("250x200")
  214. EasyBox3.title("Sn Easy")
  215. EasyBox3.withdraw()
  216.  
  217. ModerateBox3 = Tkinter.Tk()
  218. ModerateBox3.geometry("250x200")
  219. ModerateBox3.title("Sn Moderate")
  220. ModerateBox3.withdraw()
  221.  
  222. HardBox3 = Tkinter.Tk()
  223. HardBox3.geometry("250x200")
  224. HardBox3.title("Sn Hard")
  225. HardBox3.withdraw()
  226.  
  227. #Eng difficulty
  228. EasyBox4 = Tkinter.Tk()
  229. EasyBox4.geometry("250x200")
  230. EasyBox4.title("Eng Easy")
  231. EasyBox4.withdraw()
  232.  
  233. ModerateBox4 = Tkinter.Tk()
  234. ModerateBox4.geometry("250x200")
  235. ModerateBox4.title("Eng Moderate")
  236. ModerateBox4.withdraw()
  237.  
  238. HardBox4 = Tkinter.Tk()
  239. HardBox4.geometry("250x200")
  240. HardBox4.title("Eng Hard")
  241. HardBox4.withdraw()
  242.  
  243.  
  244.  
  245.  
  246. def Math():
  247. MenuBox.withdraw()
  248. MathBox.deiconify()
  249. return
  250. def Bm():
  251. MenuBox.withdraw()
  252. BmBox.deiconify()
  253. return
  254. def Sn():
  255. MenuBox.withdraw()
  256. SnBox.deiconify()
  257. return
  258. def Eng():
  259. MenuBox.withdraw()
  260. EngBox.deiconify()
  261. return
  262. def back1():
  263. MathBox.withdraw()
  264. EngBox.withdraw()
  265. SnBox.withdraw()
  266. BmBox.withdraw()
  267. MenuBox.deiconify()
  268. return
  269.  
  270.  
  271. #def startbutton in MathBox
  272. def start1():
  273. if not var.get():
  274. tkMessageBox.showerror('Choose One')
  275. elif var.get()== 1:
  276. MathBox.withdraw()
  277. EasyBox1.deiconify()
  278. tkMessageBox.showinfo('Goodluck')
  279. elif var.get()==2:
  280. MathBox.withdraw()
  281. ModerateBox1.deiconify()
  282. tkMessageBox.showinfo('Goodluck')
  283. else:
  284. MathBox.withdraw()
  285. HardBox1.deiconify()
  286. tkMessageBox.showinfo('Goodluck')
  287. return
  288.  
  289. #radiobutton for MathBox
  290. from Tkinter import *
  291.  
  292. def sel1(number):
  293. var.set(number)
  294. selection = "You selected the option " + str(var.get())
  295. label.config(text = selection)
  296.  
  297. MathBox = Tk()
  298. MathBox.geometry("250x200")
  299. MathBox.title("Math")
  300. var = IntVar()
  301.  
  302. R1 = Radiobutton(MathBox, text="Easy", variable=var, value=1,
  303. command=lambda: sel1(1))
  304. R1.pack( anchor = W)
  305.  
  306. R2 = Radiobutton(MathBox, text="Moderate", variable=var, value=2,
  307. command=lambda: sel1(2))
  308. R2.pack( anchor = W )
  309.  
  310. R3 = Radiobutton(MathBox, text="Hard", variable=var, value=3,
  311. command=lambda: sel1(3))
  312. R3.pack( anchor = W)
  313.  
  314.  
  315. label = Label(MathBox)
  316. label.pack()
  317.  
  318. MathBox.withdraw()
  319.  
  320. #def startbutton in BmBox
  321. def start2():
  322. if not var.get():
  323. tkMessageBox.showerror('Choose One')
  324. elif var.get()== 1:
  325. BmBox.withdraw()
  326. EasyBox2.deiconify()
  327. tkMessageBox.showinfo('Goodluck')
  328. elif var.get()==2:
  329. BmBox.withdraw()
  330. ModerateBox2.deiconify()
  331. tkMessageBox.showinfo('Goodluck')
  332. else:
  333. BmBox.withdraw()
  334. HardBox2.deiconify()
  335. tkMessageBox.showinfo('Goodluck')
  336. return
  337.  
  338. #radionbutton for BM
  339.  
  340. from Tkinter import *
  341.  
  342. def sel2(number):
  343. var.set(number)
  344. selection = "You selected the option " + str(var.get())
  345. label.config(text = selection)
  346.  
  347. BmBox = Tk()
  348. BmBox.geometry("250x200")
  349. BmBox.title("Bm")
  350. var = IntVar()
  351.  
  352. R1 = Radiobutton(BmBox, text="Easy", variable=var, value=1,
  353. command=lambda: sel2(1))
  354. R1.pack( anchor = W)
  355.  
  356. R2 = Radiobutton(BmBox, text="Moderate", variable=var, value=2,
  357. command=lambda: sel2(2))
  358. R2.pack( anchor = W )
  359.  
  360. R3 = Radiobutton(BmBox, text="Hard", variable=var, value=3,
  361. command=lambda: sel2(3))
  362. R3.pack( anchor = W)
  363.  
  364.  
  365. label = Label(BmBox)
  366. label.pack()
  367.  
  368. BmBox.withdraw()
  369.  
  370. #def startbutton in SnBox
  371. def start3():
  372. if not var.get():
  373. tkMessageBox.showerror('Choose One')
  374. elif var.get()== 1:
  375. SnBox.withdraw()
  376. EasyBox3.deiconify()
  377. tkMessageBox.showinfo('Goodluck')
  378. elif var.get()==2:
  379. SnBox.withdraw()
  380. ModerateBox3.deiconify()
  381. tkMessageBox.showinfo('Goodluck')
  382. else:
  383. SnBox.withdraw()
  384. HardBox3.deiconify()
  385. tkMessageBox.showinfo('Goodluck')
  386. return
  387.  
  388. #radionbutton for Sn
  389.  
  390. from Tkinter import *
  391.  
  392. def sel(number):
  393. var.set(number)
  394. selection = "You selected the option " + str(var.get())
  395. label.config(text = selection)
  396.  
  397. SnBox = Tk()
  398. SnBox.geometry("250x200")
  399. SnBox.title("Science")
  400. var = IntVar()
  401.  
  402. R1 = Radiobutton(SnBox, text="Easy", variable=var, value=1,
  403. command=lambda: sel(1))
  404. R1.pack( anchor = W)
  405.  
  406. R2 = Radiobutton(SnBox, text="Moderate", variable=var, value=2,
  407. command=lambda: sel(2))
  408. R2.pack( anchor = W )
  409.  
  410. R3 = Radiobutton(SnBox, text="Hard", variable=var, value=3,
  411. command=lambda: sel(3))
  412. R3.pack( anchor = W)
  413.  
  414.  
  415.  
  416. label = Label(SnBox)
  417. label.pack()
  418.  
  419.  
  420. SnBox.withdraw()
  421.  
  422. #def startbutton in EngBox
  423. def start4():
  424. if not var.get():
  425. tkMessageBox.showerror('Choose One')
  426. elif var.get()== 1:
  427. EngBox.withdraw()
  428. EasyBox4.deiconify()
  429. tkMessageBox.showinfo('Goodluck')
  430. elif var.get()==2:
  431. EngBox.withdraw()
  432. ModerateBox4.deiconify()
  433. tkMessageBox.showinfo('Goodluck')
  434. else:
  435. EngBox.withdraw()
  436. HardBox4.deiconify()
  437. tkMessageBox.showinfo('Goodluck')
  438. return
  439.  
  440. #radiobutton for eng
  441. from Tkinter import *
  442.  
  443. def sel(number):
  444. var.set(number)
  445. selection = "You selected the option " + str(var.get())
  446. label.config(text = selection)
  447.  
  448. EngBox = Tk()
  449. EngBox.geometry("250x200")
  450. EngBox.title("English")
  451. var = IntVar()
  452.  
  453. R1 = Radiobutton(EngBox, text="Easy", variable=var, value=1,
  454. command=lambda: sel(1))
  455. R1.pack( anchor = W)
  456.  
  457. R2 = Radiobutton(EngBox, text="Moderate", variable=var, value=2,
  458. command=lambda: sel(2))
  459. R2.pack( anchor = W )
  460.  
  461. R3 = Radiobutton(EngBox, text="Hard", variable=var, value=3,
  462. command=lambda: sel(3))
  463. R3.pack( anchor = W)
  464.  
  465.  
  466. label = Label(EngBox)
  467. label.pack()
  468.  
  469. EngBox.withdraw()
  470.  
  471. #All button
  472. Tkinter.Button (RegBox, text="Back", command=back).pack()
  473. Tkinter.Button (RegBox, text="Enter", command=save).pack()
  474. Tkinter.Button (WindowBox, text="Register", command=register).pack()
  475. Tkinter.Button (WindowBox, text="Proceed", command=read).pack()
  476. Tkinter.Button (MenuBox, text="Math",command=Math,width=15).place(relx=.0,rely=.2)
  477. Tkinter.Button (MenuBox, text="Bm",command=Bm,width=15).place(relx=.0,rely=.4)
  478. Tkinter.Button (MenuBox, text="Science",command=Sn,width=15).place(relx=.5, rely=.2)
  479. Tkinter.Button (MenuBox, text="Eng",command=Eng,width=15).place(relx=.5,rely=.4)
  480. Tkinter.Button (MathBox, text="Back", command=back1).place(relx=.4,rely=.7)
  481. Tkinter.Button (EngBox, text="Back", command=back1).place(relx=.4,rely=.7)
  482. Tkinter.Button (BmBox, text="Back", command=back1).place(relx=.4,rely=.7)
  483. Tkinter.Button (SnBox, text="Back", command=back1).place(relx=.4,rely=.7)
  484. Tkinter.Button (MathBox, text="Start",command=start1).pack(side=RIGHT)
  485. Tkinter.Button (BmBox, text="Start",command=start2).pack(side=RIGHT)
  486. Tkinter.Button (SnBox, text="Start",command=start3).pack(side=RIGHT)
  487. Tkinter.Button (EngBox, text="Start",command=start4).pack(side=RIGHT)
  488.  
  489. WindowBox.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement