Prześlij pliki do ''
This commit is contained in:
parent
108143c76d
commit
40b55ade06
683
main_v_3.0.py
Normal file
683
main_v_3.0.py
Normal file
@ -0,0 +1,683 @@
|
|||||||
|
from tkinter import *
|
||||||
|
import tkinter as tk
|
||||||
|
import pymysql as mysql
|
||||||
|
import socket
|
||||||
|
import random
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
|
||||||
|
def admin():
|
||||||
|
def edit_baza_pytan():
|
||||||
|
edit_baza_pytan_window = tk.Tk()
|
||||||
|
edit_baza_pytan_window.geometry('600x300+300+300')
|
||||||
|
|
||||||
|
def add_pyt_sql():
|
||||||
|
add_pytanie.destroy()
|
||||||
|
del_pytanie.destroy()
|
||||||
|
|
||||||
|
def add_pyt():
|
||||||
|
print("ok")
|
||||||
|
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
cur1 = con.cursor()
|
||||||
|
|
||||||
|
|
||||||
|
if(pytanie_entry.get()=='' or p_odp.get()=='' or b_odp_1.get()=='' or b_odp_2.get()=='' or b_odp_3.get()==''):
|
||||||
|
err = tk.Label(edit_baza_pytan_window, text='Wypełnij puste pola')
|
||||||
|
err.grid(row=7)
|
||||||
|
else:
|
||||||
|
cur1.execute('SELECT id_pytania FROM pytania')
|
||||||
|
wyniki = cur1.fetchall()
|
||||||
|
x = len(wyniki)
|
||||||
|
|
||||||
|
cur.execute(
|
||||||
|
"INSERT INTO pytania (id_pytania, Pytanie, P_odp, B_odp_1, B_odp_2, B_odp_3) VALUES ('%s','%s','%s','%s','%s','%s')" % (
|
||||||
|
x+1, pytanie_entry.get(), p_odp.get(), b_odp_1.get(),
|
||||||
|
b_odp_2.get(), b_odp_3.get()))
|
||||||
|
|
||||||
|
con.commit()
|
||||||
|
|
||||||
|
cur.close()
|
||||||
|
cur1.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
add_pyt_sql()
|
||||||
|
|
||||||
|
pytanie_entry_label = tk.Label(edit_baza_pytan_window, text='Pytanie')
|
||||||
|
p_odp_label = tk.Label(edit_baza_pytan_window, text='Poprawna odpowiedz')
|
||||||
|
b_odp_1_label = tk.Label(edit_baza_pytan_window, text='Bledna odpowiedz')
|
||||||
|
b_odp_2_label = tk.Label(edit_baza_pytan_window, text='Bledna odpowiedz')
|
||||||
|
b_odp_3_label = tk.Label(edit_baza_pytan_window, text='Bledna odpowiedz')
|
||||||
|
|
||||||
|
pytanie_entry = tk.Entry(edit_baza_pytan_window, )
|
||||||
|
p_odp = tk.Entry(edit_baza_pytan_window, )
|
||||||
|
b_odp_1 = tk.Entry(edit_baza_pytan_window, )
|
||||||
|
b_odp_2 = tk.Entry(edit_baza_pytan_window, )
|
||||||
|
b_odp_3 = tk.Entry(edit_baza_pytan_window, )
|
||||||
|
|
||||||
|
add_pytanie_button = tk.Button(
|
||||||
|
edit_baza_pytan_window,
|
||||||
|
text='Dodaj pytanie',
|
||||||
|
command=add_pyt)
|
||||||
|
|
||||||
|
pytanie_entry_label.grid(row=0, column=0)
|
||||||
|
p_odp_label.grid(row=1, column=0)
|
||||||
|
b_odp_1_label.grid(row=2, column=0)
|
||||||
|
b_odp_2_label.grid(row=3, column=0)
|
||||||
|
b_odp_3_label.grid(row=4, column=0)
|
||||||
|
|
||||||
|
pytanie_entry.grid(row=0, column=1)
|
||||||
|
p_odp.grid(row=1, column=1)
|
||||||
|
b_odp_1.grid(row=2, column=1)
|
||||||
|
b_odp_2.grid(row=3, column=1)
|
||||||
|
b_odp_3.grid(row=4, column=1)
|
||||||
|
|
||||||
|
add_pytanie_button.grid(row=5, column=1)
|
||||||
|
|
||||||
|
def del_pyt_sql():
|
||||||
|
add_pytanie.destroy()
|
||||||
|
del_pytanie.destroy()
|
||||||
|
|
||||||
|
def del_pyt():
|
||||||
|
print("ok")
|
||||||
|
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
cur.execute(
|
||||||
|
"DELETE FROM `pytania` WHERE `id_pytania` = %s" % int(id_pyt.get()))
|
||||||
|
|
||||||
|
con.commit()
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
del_pyt_sql()
|
||||||
|
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
cur.execute(
|
||||||
|
"SELECT * FROM `pytania`")
|
||||||
|
|
||||||
|
wyniki = cur.fetchall()
|
||||||
|
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
simple_label2 = tk.Label(edit_baza_pytan_window, text='Id | Pytanie | Odpowiedz | Odpowiedz | Odpowiedz')
|
||||||
|
simple_label2.grid(row=0, column=0)
|
||||||
|
|
||||||
|
listbox = Listbox(edit_baza_pytan_window, width= 70)
|
||||||
|
a = 0
|
||||||
|
for list in wyniki:
|
||||||
|
text = "%s | %s | %s | %s | %s | %s" % (wyniki[a][0],wyniki[a][1], wyniki[a][2], wyniki[a][3], wyniki[a][4], wyniki[a][5])
|
||||||
|
listbox.insert(END, text)
|
||||||
|
a += 1
|
||||||
|
listbox.grid(row=1, column=0)
|
||||||
|
scrollbar = Scrollbar(edit_baza_pytan_window, orient='vertical', command=listbox.yview)
|
||||||
|
scrollbar.grid(row=1, column=1, stick='ns')
|
||||||
|
|
||||||
|
simple_label = tk.Label(edit_baza_pytan_window, text='Podaj nr do usuniecia')
|
||||||
|
simple_label.grid(row=2, column=0)
|
||||||
|
id_pyt = tk.Entry(edit_baza_pytan_window)
|
||||||
|
id_pyt.grid(row=3, column=0)
|
||||||
|
|
||||||
|
del_pytanie_button = tk.Button(
|
||||||
|
edit_baza_pytan_window,
|
||||||
|
text='Usun',
|
||||||
|
command=del_pyt)
|
||||||
|
|
||||||
|
del_pytanie_button.grid(row=4, column=0)
|
||||||
|
|
||||||
|
add_pytanie = tk.Button(
|
||||||
|
edit_baza_pytan_window,
|
||||||
|
text='Dodaj pytanie do bazy',
|
||||||
|
command=add_pyt_sql)
|
||||||
|
add_pytanie.grid(row=0, column=0)
|
||||||
|
|
||||||
|
del_pytanie = tk.Button(
|
||||||
|
edit_baza_pytan_window,
|
||||||
|
text='Usuń pytanie z bazy',
|
||||||
|
command=del_pyt_sql)
|
||||||
|
del_pytanie.grid(row=1, column=0)
|
||||||
|
|
||||||
|
edit_baza_pytan_window.mainloop()
|
||||||
|
|
||||||
|
def wyniki_window():
|
||||||
|
wyniki_window = tk.Tk()
|
||||||
|
|
||||||
|
def filtr_wynik():
|
||||||
|
if(nazwa_quizu_entry.get() != '' and nazwa_ucznia_entry.get() == ''):
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
cur.execute(
|
||||||
|
'SELECT * FROM wyniki where quiz_nazwa = \'%s\'' % (nazwa_quizu_entry.get()))
|
||||||
|
wyniki = cur.fetchall()
|
||||||
|
|
||||||
|
listbox = Listbox(wyniki_window, width=50)
|
||||||
|
listbox.grid(row=0, columnspan=2)
|
||||||
|
scrollbar = Scrollbar(wyniki_window, orient='vertical', command=listbox.yview)
|
||||||
|
scrollbar.grid(row=0, columnspan=2, stick='ens')
|
||||||
|
a = 0
|
||||||
|
for list in wyniki:
|
||||||
|
listbox.insert(a, list)
|
||||||
|
a += 1
|
||||||
|
listbox.config(yscrollcommand=scrollbar.set)
|
||||||
|
scrollbar.config(command=listbox.yview)
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
elif(nazwa_quizu_entry.get() == '' and nazwa_ucznia_entry.get() != ''):
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
cur.execute(
|
||||||
|
'SELECT * FROM wyniki where user_nazwa = \'%s\'' % (nazwa_ucznia_entry.get()))
|
||||||
|
wyniki = cur.fetchall()
|
||||||
|
|
||||||
|
listbox = Listbox(wyniki_window, width=50)
|
||||||
|
listbox.grid(row=0, columnspan=2)
|
||||||
|
scrollbar = Scrollbar(wyniki_window, orient='vertical', command=listbox.yview)
|
||||||
|
scrollbar.grid(row=0, columnspan=2, stick='ens')
|
||||||
|
a = 0
|
||||||
|
for list in wyniki:
|
||||||
|
listbox.insert(a, list)
|
||||||
|
a += 1
|
||||||
|
listbox.config(yscrollcommand=scrollbar.set)
|
||||||
|
scrollbar.config(command=listbox.yview)
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
elif(nazwa_quizu_entry.get() != '' and nazwa_ucznia_entry.get() != ''):
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
cur.execute(
|
||||||
|
'SELECT * FROM wyniki where quiz_nazwa = \'%s\' AND user_nazwa = \'%s\'' % (nazwa_quizu_entry.get(),nazwa_ucznia_entry.get()))
|
||||||
|
wyniki = cur.fetchall()
|
||||||
|
|
||||||
|
listbox = Listbox(wyniki_window, width=50)
|
||||||
|
listbox.grid(row=0, columnspan=2)
|
||||||
|
scrollbar = Scrollbar(wyniki_window, orient='vertical', command=listbox.yview)
|
||||||
|
scrollbar.grid(row=0, columnspan=2, stick='ens')
|
||||||
|
a = 0
|
||||||
|
for list in wyniki:
|
||||||
|
listbox.insert(a, list)
|
||||||
|
a += 1
|
||||||
|
listbox.config(yscrollcommand=scrollbar.set)
|
||||||
|
scrollbar.config(command=listbox.yview)
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("pusty filtr")
|
||||||
|
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
cur.execute(
|
||||||
|
"SELECT * FROM `wyniki`")
|
||||||
|
|
||||||
|
wyniki = cur.fetchall()
|
||||||
|
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
listbox = Listbox(wyniki_window, width=50)
|
||||||
|
listbox.grid(row=0,columnspan=2)
|
||||||
|
scrollbar = Scrollbar(wyniki_window, orient= 'vertical', command=listbox.yview)
|
||||||
|
scrollbar.grid(row=0,columnspan=2, stick='ens')
|
||||||
|
a = 0
|
||||||
|
for list in wyniki:
|
||||||
|
listbox.insert(a, list)
|
||||||
|
a += 1
|
||||||
|
listbox.config(yscrollcommand = scrollbar.set)
|
||||||
|
scrollbar.config(command = listbox.yview)
|
||||||
|
|
||||||
|
simple_label = tk.Label(wyniki_window, text='Pozostaw puste pole by nie uwzglednic')
|
||||||
|
simple_label.grid(row=1, columnspan=2, stick= 'we')
|
||||||
|
|
||||||
|
simple_label_1 = tk.Label(wyniki_window, text='Nazwa quizu')
|
||||||
|
simple_label_1.grid(row=2, column=0)
|
||||||
|
nazwa_quizu_entry = tk.Entry(wyniki_window)
|
||||||
|
nazwa_quizu_entry.grid(row=2, column=1)
|
||||||
|
|
||||||
|
simple_label_2 = tk.Label(wyniki_window, text='Nazwa ucznia')
|
||||||
|
simple_label_2.grid(row=3, column=0)
|
||||||
|
nazwa_ucznia_entry = tk.Entry(wyniki_window)
|
||||||
|
nazwa_ucznia_entry.grid(row=3, column=1)
|
||||||
|
|
||||||
|
filtr_button = tk.Button(
|
||||||
|
wyniki_window,
|
||||||
|
text='Filtruj',
|
||||||
|
command=filtr_wynik)
|
||||||
|
filtr_button.grid(row=4, columnspan=2, stick = 'we')
|
||||||
|
|
||||||
|
wyniki_window.mainloop()
|
||||||
|
|
||||||
|
def add_quiz_window():
|
||||||
|
add_quiz_window = tk.Tk()
|
||||||
|
|
||||||
|
def add_sql():
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur1 = con.cursor()
|
||||||
|
cur2 = con.cursor()
|
||||||
|
cur3 = con.cursor()
|
||||||
|
cur4 = con.cursor()
|
||||||
|
cur5 = con.cursor()
|
||||||
|
cur6 = con.cursor()
|
||||||
|
|
||||||
|
cur1.execute(
|
||||||
|
"INSERT INTO `quiz` (`quiz_nazwa`) VALUES ('%s')" % (quiz_nazwa.get()))
|
||||||
|
cur2.execute(
|
||||||
|
"INSERT INTO pytania_quiz (quiz_nazwa, pytanie, p_odp, b_odp_1, b_odp_2, b_odp_3) VALUES ('%s','%s','%s','%s','%s','%s')"
|
||||||
|
% (quiz_nazwa.get(), p1.get(), p_odp_1.get(), b_odp_1_1.get(), b_odp_1_2.get(), b_odp_1_3.get()))
|
||||||
|
cur3.execute(
|
||||||
|
"INSERT INTO pytania_quiz (quiz_nazwa, pytanie, p_odp, b_odp_1, b_odp_2, b_odp_3) VALUES ('%s','%s','%s','%s','%s','%s')"
|
||||||
|
% (quiz_nazwa.get(), p2.get(), p_odp_2.get(), b_odp_2_1.get(), b_odp_2_2.get(), b_odp_2_3.get()))
|
||||||
|
cur4.execute(
|
||||||
|
"INSERT INTO pytania_quiz (quiz_nazwa, pytanie, p_odp, b_odp_1, b_odp_2, b_odp_3) VALUES ('%s','%s','%s','%s','%s','%s')"
|
||||||
|
% (quiz_nazwa.get(), p3.get(), p_odp_3.get(), b_odp_3_1.get(), b_odp_3_2.get(), b_odp_3_3.get()))
|
||||||
|
cur5.execute(
|
||||||
|
"INSERT INTO pytania_quiz (quiz_nazwa, pytanie, p_odp, b_odp_1, b_odp_2, b_odp_3) VALUES ('%s','%s','%s','%s','%s','%s')"
|
||||||
|
% (quiz_nazwa.get(), p4.get(), p_odp_4.get(), b_odp_4_1.get(), b_odp_4_2.get(), b_odp_4_3.get()))
|
||||||
|
cur6.execute(
|
||||||
|
"INSERT INTO pytania_quiz (quiz_nazwa, pytanie, p_odp, b_odp_1, b_odp_2, b_odp_3) VALUES ('%s','%s','%s','%s','%s','%s')"
|
||||||
|
% (quiz_nazwa.get(), p5.get(), p_odp_5.get(), b_odp_5_1.get(), b_odp_5_2.get(), b_odp_5_3.get()))
|
||||||
|
|
||||||
|
con.commit()
|
||||||
|
cur1.close()
|
||||||
|
cur2.close()
|
||||||
|
cur3.close()
|
||||||
|
cur4.close()
|
||||||
|
cur5.close()
|
||||||
|
cur6.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
tk.Label(add_quiz_window, text='Nazwa quizu').grid(row=0, column=0)
|
||||||
|
|
||||||
|
for x in range(1,6):
|
||||||
|
tk.Label(add_quiz_window, text='Pytanie').grid(row=x, column=0)
|
||||||
|
tk.Label(add_quiz_window, text='Poprawna odp').grid(row=x, column=2)
|
||||||
|
for y in range(4,9):
|
||||||
|
if (y%2==1):
|
||||||
|
continue
|
||||||
|
tk.Label(add_quiz_window, text='Bledna odp').grid(row=x, column=y)
|
||||||
|
|
||||||
|
quiz_nazwa = tk.Entry(add_quiz_window)
|
||||||
|
quiz_nazwa.grid(row=0, column=1)
|
||||||
|
|
||||||
|
|
||||||
|
p1 = tk.Entry(add_quiz_window)
|
||||||
|
p1.grid(row=1, column=1)
|
||||||
|
|
||||||
|
p_odp_1 = tk.Entry(add_quiz_window)
|
||||||
|
p_odp_1.grid(row=1, column=3)
|
||||||
|
|
||||||
|
b_odp_1_1 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_1_1.grid(row=1, column=5)
|
||||||
|
|
||||||
|
b_odp_1_2 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_1_2.grid(row=1, column=7)
|
||||||
|
|
||||||
|
b_odp_1_3 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_1_3.grid(row=1, column=9)
|
||||||
|
|
||||||
|
""""""
|
||||||
|
|
||||||
|
p2 = tk.Entry(add_quiz_window)
|
||||||
|
p2.grid(row=2, column=1)
|
||||||
|
|
||||||
|
p_odp_2 = tk.Entry(add_quiz_window)
|
||||||
|
p_odp_2.grid(row=2, column=3)
|
||||||
|
|
||||||
|
b_odp_2_1 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_2_1.grid(row=2, column=5)
|
||||||
|
|
||||||
|
b_odp_2_2 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_2_2.grid(row=2, column=7)
|
||||||
|
|
||||||
|
b_odp_2_3 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_2_3.grid(row=2, column=9)
|
||||||
|
|
||||||
|
""""""
|
||||||
|
|
||||||
|
p3 = tk.Entry(add_quiz_window)
|
||||||
|
p3.grid(row=3, column=1)
|
||||||
|
|
||||||
|
p_odp_3 = tk.Entry(add_quiz_window)
|
||||||
|
p_odp_3.grid(row=3, column=3)
|
||||||
|
|
||||||
|
b_odp_3_1 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_3_1.grid(row=3, column=5)
|
||||||
|
|
||||||
|
b_odp_3_2 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_3_2.grid(row=3, column=7)
|
||||||
|
|
||||||
|
b_odp_3_3 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_3_3.grid(row=3, column=9)
|
||||||
|
|
||||||
|
""""""
|
||||||
|
|
||||||
|
p4 = tk.Entry(add_quiz_window)
|
||||||
|
p4.grid(row=4, column=1)
|
||||||
|
|
||||||
|
p_odp_4 = tk.Entry(add_quiz_window)
|
||||||
|
p_odp_4.grid(row=4, column=3)
|
||||||
|
|
||||||
|
b_odp_4_1 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_4_1.grid(row=4, column=5)
|
||||||
|
|
||||||
|
b_odp_4_2 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_4_2.grid(row=4, column=7)
|
||||||
|
|
||||||
|
b_odp_4_3 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_4_3.grid(row=4, column=9)
|
||||||
|
|
||||||
|
""""""
|
||||||
|
|
||||||
|
p5 = tk.Entry(add_quiz_window)
|
||||||
|
p5.grid(row=5, column=1)
|
||||||
|
|
||||||
|
p_odp_5 = tk.Entry(add_quiz_window)
|
||||||
|
p_odp_5.grid(row=5, column=3)
|
||||||
|
|
||||||
|
b_odp_5_1 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_5_1.grid(row=5, column=5)
|
||||||
|
|
||||||
|
b_odp_5_2 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_5_2.grid(row=5, column=7)
|
||||||
|
|
||||||
|
b_odp_5_3 = tk.Entry(add_quiz_window)
|
||||||
|
b_odp_5_3.grid(row=5, column=9)
|
||||||
|
|
||||||
|
submit_button = tk.Button(
|
||||||
|
add_quiz_window,
|
||||||
|
text='Prześlij',
|
||||||
|
command=add_sql)
|
||||||
|
submit_button.grid(columnspan=2, stick='we')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
add_quiz_window.mainloop()
|
||||||
|
|
||||||
|
edit_db=tk.Button(
|
||||||
|
root,
|
||||||
|
width = 30,
|
||||||
|
heigh = 5,
|
||||||
|
text = 'Edytuj baze pytan',
|
||||||
|
command = edit_baza_pytan)
|
||||||
|
edit_db.grid(row=2, column=1)
|
||||||
|
|
||||||
|
wyniki=tk.Button(
|
||||||
|
root,
|
||||||
|
width=30,
|
||||||
|
heigh=5,
|
||||||
|
text = 'Wyniki',
|
||||||
|
command = wyniki_window)
|
||||||
|
wyniki.grid(row=3,column=1)
|
||||||
|
|
||||||
|
okno_add_quiz = tk.Button(
|
||||||
|
root,
|
||||||
|
width=30,
|
||||||
|
heigh=5,
|
||||||
|
text='Utwórz quiz',
|
||||||
|
command=add_quiz_window)
|
||||||
|
okno_add_quiz.grid(row=4, column=1)
|
||||||
|
|
||||||
|
|
||||||
|
def user():
|
||||||
|
|
||||||
|
def wyniki_window():
|
||||||
|
wyniki_window = tk.Tk()
|
||||||
|
|
||||||
|
def wyniki():
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
cur.execute(
|
||||||
|
"SELECT quiz_nazwa, l_pkt FROM wyniki WHERE user_nazwa = \'%s\'" % (imie_entry.get()))
|
||||||
|
|
||||||
|
wyniki = cur.fetchall()
|
||||||
|
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
listbox = Listbox(wyniki_window)
|
||||||
|
a = 0
|
||||||
|
for list in wyniki:
|
||||||
|
listbox.insert(a, list)
|
||||||
|
a += 1
|
||||||
|
listbox.grid(row=5)
|
||||||
|
scrollbar = Scrollbar(wyniki_window, orient='vertical', command=listbox.yview)
|
||||||
|
scrollbar.grid(row=5, columnspan=2, stick='ens')
|
||||||
|
listbox.config(yscrollcommand=scrollbar.set)
|
||||||
|
scrollbar.config(command=listbox.yview)
|
||||||
|
|
||||||
|
tk.Label(wyniki_window, text='Podaj imie').grid()
|
||||||
|
imie_entry = tk.Entry(wyniki_window)
|
||||||
|
imie_entry.grid()
|
||||||
|
|
||||||
|
wyniki_button = tk.Button(
|
||||||
|
wyniki_window,
|
||||||
|
text='Wyniki',
|
||||||
|
command=wyniki)
|
||||||
|
wyniki_button.grid(row=4, columnspan=2, stick='we')
|
||||||
|
|
||||||
|
wyniki_window.mainloop()
|
||||||
|
|
||||||
|
def random_pytanie_window():
|
||||||
|
random_pytanie_window = tk.Tk()
|
||||||
|
|
||||||
|
print('ok')
|
||||||
|
|
||||||
|
def start():
|
||||||
|
|
||||||
|
def spr_b10(okno):
|
||||||
|
if(okno==wynik[0][2]):
|
||||||
|
button_10.configure(bg='green')
|
||||||
|
else:
|
||||||
|
button_10.configure(bg='red')
|
||||||
|
|
||||||
|
def spr_b11(okno):
|
||||||
|
if(okno==wynik[0][2]):
|
||||||
|
button_11.configure(bg='green')
|
||||||
|
else:
|
||||||
|
button_11.configure(bg='red')
|
||||||
|
|
||||||
|
def spr_b20(okno):
|
||||||
|
if(okno==wynik[0][2]):
|
||||||
|
button_20.configure(bg='green')
|
||||||
|
else:
|
||||||
|
button_20.configure(bg='red')
|
||||||
|
|
||||||
|
def spr_b21(okno):
|
||||||
|
if(okno==wynik[0][2]):
|
||||||
|
button_21.configure(bg='green')
|
||||||
|
else:
|
||||||
|
button_21.configure(bg='red')
|
||||||
|
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
cur1 = con.cursor()
|
||||||
|
|
||||||
|
cur.execute('SELECT id_pytania FROM pytania')
|
||||||
|
dlugosc = cur.fetchall()
|
||||||
|
x = len(dlugosc)
|
||||||
|
rand = random.randint(1, x)
|
||||||
|
|
||||||
|
cur1.execute('SELECT * FROM pytania WHERE id_pytania = %s' % (rand))
|
||||||
|
wynik = cur1.fetchall()
|
||||||
|
|
||||||
|
con.commit()
|
||||||
|
cur.close()
|
||||||
|
cur1.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
simple_label = tk.Label(random_pytanie_window, text=wynik[0][1], width=30)
|
||||||
|
simple_label.grid(row=0, columnspan=2, stick='we')
|
||||||
|
|
||||||
|
button_10 = tk.Button(
|
||||||
|
random_pytanie_window,
|
||||||
|
text=wynik[0][2],
|
||||||
|
command=lambda:spr_b10(wynik[0][2]))
|
||||||
|
button_10.grid(row=1, column=0, stick='we')
|
||||||
|
|
||||||
|
button_11 = tk.Button(
|
||||||
|
random_pytanie_window,
|
||||||
|
text=wynik[0][3],
|
||||||
|
command=lambda:spr_b11(wynik[0][3]))
|
||||||
|
button_11.grid(row=1, column=1, stick='we')
|
||||||
|
|
||||||
|
button_20 = tk.Button(
|
||||||
|
random_pytanie_window,
|
||||||
|
text=wynik[0][4],
|
||||||
|
command=lambda:spr_b20(wynik[0][4]))
|
||||||
|
button_20.grid(row=2, column=0, stick='we')
|
||||||
|
|
||||||
|
button_21 = tk.Button(
|
||||||
|
random_pytanie_window,
|
||||||
|
text=wynik[0][5],
|
||||||
|
command=lambda:spr_b21(wynik[0][5]))
|
||||||
|
button_21.grid(row=2, column=1, stick='we')
|
||||||
|
|
||||||
|
button_next = tk.Button(
|
||||||
|
random_pytanie_window,
|
||||||
|
text='Next',
|
||||||
|
command=start)
|
||||||
|
button_next.grid(row=3, columnspan=2, stick='we')
|
||||||
|
|
||||||
|
|
||||||
|
start()
|
||||||
|
|
||||||
|
random_pytanie_window.mainloop()
|
||||||
|
|
||||||
|
def quiz_window():
|
||||||
|
|
||||||
|
quiz_window = tk.Tk()
|
||||||
|
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
cur.execute('SELECT quiz_nazwa FROM quiz')
|
||||||
|
wynik = cur.fetchall()
|
||||||
|
con.commit()
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
global i
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
def nast():
|
||||||
|
global i
|
||||||
|
i=i+5
|
||||||
|
start()
|
||||||
|
|
||||||
|
def ok(): print('ok')
|
||||||
|
|
||||||
|
def start():
|
||||||
|
print(i)
|
||||||
|
|
||||||
|
button_10 = tk.Button(
|
||||||
|
quiz_window,
|
||||||
|
text=wynik[i][0],
|
||||||
|
width=10,
|
||||||
|
heigh=5,
|
||||||
|
command=ok)
|
||||||
|
button_10.grid(row=1, column=0, stick='we')
|
||||||
|
|
||||||
|
button_11 = tk.Button(
|
||||||
|
quiz_window,
|
||||||
|
text=wynik[i+1][0],
|
||||||
|
width=10,
|
||||||
|
heigh=5,
|
||||||
|
command=ok)
|
||||||
|
button_11.grid(row=1, column=1, stick='we')
|
||||||
|
|
||||||
|
button_12 = tk.Button(
|
||||||
|
quiz_window,
|
||||||
|
text=wynik[i+2][0],
|
||||||
|
width=10,
|
||||||
|
heigh=5,
|
||||||
|
command=ok)
|
||||||
|
button_12.grid(row=1, column=2, stick='we')
|
||||||
|
|
||||||
|
button_20 = tk.Button(
|
||||||
|
quiz_window,
|
||||||
|
text=wynik[i+3][0],
|
||||||
|
width=10,
|
||||||
|
heigh=5,
|
||||||
|
command=ok)
|
||||||
|
button_20.grid(row=2, column=0, stick='we')
|
||||||
|
|
||||||
|
button_21 = tk.Button(
|
||||||
|
quiz_window,
|
||||||
|
text=wynik[i+4][0],
|
||||||
|
width=10,
|
||||||
|
heigh=5,
|
||||||
|
command=ok)
|
||||||
|
button_21.grid(row=2, column=1, stick='we')
|
||||||
|
|
||||||
|
button_22 = tk.Button(
|
||||||
|
quiz_window,
|
||||||
|
text=wynik[i+5][0],
|
||||||
|
width=10,
|
||||||
|
heigh=5,
|
||||||
|
command=ok)
|
||||||
|
button_22.grid(row=2, column=2, stick='we')
|
||||||
|
|
||||||
|
button_next = tk.Button(
|
||||||
|
quiz_window,
|
||||||
|
text='Nastepne',
|
||||||
|
width=10,
|
||||||
|
heigh=5,
|
||||||
|
command=nast)
|
||||||
|
button_next.grid(row=3, column=1, stick='we')
|
||||||
|
|
||||||
|
start()
|
||||||
|
|
||||||
|
quiz_window.mainloop()
|
||||||
|
|
||||||
|
okno_wyniki = tk.Button(
|
||||||
|
root,
|
||||||
|
width=30,
|
||||||
|
heigh=5,
|
||||||
|
text='Wyniki',
|
||||||
|
command=wyniki_window)
|
||||||
|
okno_wyniki.grid()
|
||||||
|
|
||||||
|
okno_random_pyt = tk.Button(
|
||||||
|
root,
|
||||||
|
width=30,
|
||||||
|
heigh=5,
|
||||||
|
text='Losuj pytanie',
|
||||||
|
command=random_pytanie_window)
|
||||||
|
okno_random_pyt.grid()
|
||||||
|
|
||||||
|
okno_quiz = tk.Button(
|
||||||
|
root,
|
||||||
|
width=30,
|
||||||
|
heigh=5,
|
||||||
|
text='quizy',
|
||||||
|
command=quiz_window)
|
||||||
|
okno_quiz.grid()
|
||||||
|
|
||||||
|
def start_app():
|
||||||
|
name = socket.gethostname()
|
||||||
|
|
||||||
|
con = mysql.Connect(host="127.0.0.1", user='root', passwd='', db='test')
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
cur.execute(
|
||||||
|
'SELECT Typ FROM users where Nazwa = \'%s\'' % name)
|
||||||
|
wynik = cur.fetchone()
|
||||||
|
|
||||||
|
if (wynik[0] == 'Admin' or wynik[0] == 'admin'):
|
||||||
|
admin()
|
||||||
|
elif(wynik[0] == 'User' or wynik[0] == 'user'):
|
||||||
|
user()
|
||||||
|
|
||||||
|
start_app()
|
||||||
|
|
||||||
|
root.mainloop()
|
109
test.sql
109
test.sql
@ -3,7 +3,7 @@
|
|||||||
-- https://www.phpmyadmin.net/
|
-- https://www.phpmyadmin.net/
|
||||||
--
|
--
|
||||||
-- Host: 127.0.0.1
|
-- Host: 127.0.0.1
|
||||||
-- Czas generowania: 01 Lut 2021, 23:02
|
-- Czas generowania: 12 Lut 2021, 19:52
|
||||||
-- Wersja serwera: 10.4.17-MariaDB
|
-- Wersja serwera: 10.4.17-MariaDB
|
||||||
-- Wersja PHP: 7.4.13
|
-- Wersja PHP: 7.4.13
|
||||||
|
|
||||||
@ -41,17 +41,16 @@ CREATE TABLE `pytania` (
|
|||||||
--
|
--
|
||||||
|
|
||||||
INSERT INTO `pytania` (`id_pytania`, `Pytanie`, `P_odp`, `B_odp_1`, `B_odp_2`, `B_odp_3`) VALUES
|
INSERT INTO `pytania` (`id_pytania`, `Pytanie`, `P_odp`, `B_odp_1`, `B_odp_2`, `B_odp_3`) VALUES
|
||||||
(1, 'Przykladowe pytanie 1', 'a', 'b', 'c', 'd'),
|
(1, 'Ile wynosi 2 + 2:', '4', '5', '3', '6'),
|
||||||
(2, 'Przykladowe pytanie 2', 'a', 'b', 'c', 'd'),
|
(2, 'Wzór na pole rombu to:', 'a * h', 'a * a', 'a * b * c', 'a^2'),
|
||||||
(3, 'Przykladowe pytanie 3', 'a', 'b', 'c', 'd'),
|
(3, 'Ile wynosi 2 + 12:', '14', '10', '12', '16'),
|
||||||
(4, 'Przykladowe pytanie 4', 'a', 'b', 'c', 'd'),
|
(4, 'Wzór na pole kwadratu to:', 'a^2', '4a', 'a * b', '2a * 2b'),
|
||||||
(5, 'Przykladowe pytanie 5', 'a', 'b', 'c', 'd'),
|
(5, 'Ile wynosi 20 + 12:', '32', '20', '12', '8'),
|
||||||
(20, 'p', 'odp', 'odp', 'odp', 'odp'),
|
(6, 'Wzór na pole trapezu to:', '(a + b) * h / 2', 'a * h / 2', '(a + b) / 2', 'h / 2'),
|
||||||
(39, 'a', 'a', 'a', 'a', 'a'),
|
(7, 'Ile wynosi 2 * 2:', '4', '8', '16', '2'),
|
||||||
(40, 'a', 'a', 'a', 'a', 'a'),
|
(8, 'Ile wynosi (x+y)(x-y):', 'x^2 - y^2', 'x^2 - y', 'x^3 - 2y', 'x - 3y'),
|
||||||
(41, 'a', 'a', 'a', 'a', 'a'),
|
(9, 'Wzór na pole trojkata to:', 'a * h / 2', 'a * h', 'a * b', 'a^2 + b^2 = c^2'),
|
||||||
(42, 'b', 'b', 'b', 'b', 'b'),
|
(10, 'Wzór na obwód kwadratu to:', '4a', 'a^4', 'a^b', 'a * b');
|
||||||
(43, 'a b', ' a', 'a', 'a', 'a');
|
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
@ -74,14 +73,11 @@ CREATE TABLE `pytania_quiz` (
|
|||||||
--
|
--
|
||||||
|
|
||||||
INSERT INTO `pytania_quiz` (`id_quiz_pytania`, `quiz_nazwa`, `pytanie`, `p_odp`, `b_odp_1`, `b_odp_2`, `b_odp_3`) VALUES
|
INSERT INTO `pytania_quiz` (`id_quiz_pytania`, `quiz_nazwa`, `pytanie`, `p_odp`, `b_odp_1`, `b_odp_2`, `b_odp_3`) VALUES
|
||||||
(1, '', '', '', '', '', ''),
|
(9, 'quiz1', 'q1_p1', 'q1_p_odp', 'q1_b_odp_1', 'q1_b_odp_2', 'q1_b_odp_3'),
|
||||||
(2, '', '', '', '', '', ''),
|
(10, 'quiz1', 'q1_p2', 'q1_p_odp', 'q1_b_odp_1', 'q1_b_odp_2', 'q1_b_odp_3'),
|
||||||
(3, '', '', '', '', '', ''),
|
(11, 'quiz1', 'q1_p3', 'q1_p_odp', 'q1_b_odp_1', 'q1_b_odp_2', 'q1_b_odp_3'),
|
||||||
(4, 'a', '', '', '', '', ''),
|
(12, 'quiz1', 'q1_p4', 'q1_p_odp', 'q1_b_odp_1', 'q1_b_odp_2', 'q1_b_odp_3'),
|
||||||
(5, 'a', '', '', '', '', ''),
|
(13, 'quiz1', 'q1_p5', 'q1_p_odp', 'q1_b_odp_1', 'q1_b_odp_2', 'q1_b_odp_3');
|
||||||
(6, 'a', '', '', '', '', ''),
|
|
||||||
(7, 'a', '', '', '', '', ''),
|
|
||||||
(8, 'a', '', '', '', '', '');
|
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
@ -99,10 +95,26 @@ CREATE TABLE `quiz` (
|
|||||||
--
|
--
|
||||||
|
|
||||||
INSERT INTO `quiz` (`id_quizu`, `quiz_nazwa`) VALUES
|
INSERT INTO `quiz` (`id_quizu`, `quiz_nazwa`) VALUES
|
||||||
(7, 'a'),
|
(16, 'quiz1'),
|
||||||
(8, 'a'),
|
(17, 'quiz2'),
|
||||||
(14, ''),
|
(18, 'quiz3'),
|
||||||
(15, 'a');
|
(19, 'quiz4'),
|
||||||
|
(20, 'quiz5'),
|
||||||
|
(21, 'quiz6'),
|
||||||
|
(22, 'quiz7'),
|
||||||
|
(23, 'quiz8'),
|
||||||
|
(24, 'quiz9'),
|
||||||
|
(25, 'quiz10'),
|
||||||
|
(26, 'quiz11'),
|
||||||
|
(27, 'quiz12'),
|
||||||
|
(28, 'quiz13'),
|
||||||
|
(29, 'quiz14'),
|
||||||
|
(30, 'quiz15'),
|
||||||
|
(31, 'quiz16'),
|
||||||
|
(32, 'quiz17'),
|
||||||
|
(33, 'quiz18'),
|
||||||
|
(34, 'quiz19'),
|
||||||
|
(35, 'quiz20');
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
@ -121,11 +133,16 @@ CREATE TABLE `users` (
|
|||||||
--
|
--
|
||||||
|
|
||||||
INSERT INTO `users` (`id_user`, `Nazwa`, `Typ`) VALUES
|
INSERT INTO `users` (`id_user`, `Nazwa`, `Typ`) VALUES
|
||||||
(1, 'Adam', 'Admin'),
|
(1, 'P01PC01', 'Admin'),
|
||||||
(2, 'Lucy', 'Admin'),
|
(2, 'P01PC04', 'User'),
|
||||||
(3, 'Kasia', 'user'),
|
(3, 'P01PC02', 'User'),
|
||||||
(4, 'Pawel', 'user'),
|
(4, 'P01PC03', 'User'),
|
||||||
(5, 'Jacob-PC1', 'admin');
|
(5, 'Jacob-PC1', 'User'),
|
||||||
|
(6, 'P02PC01', 'Admin'),
|
||||||
|
(7, 'P02PC02', 'User'),
|
||||||
|
(8, 'P02PC03', 'User'),
|
||||||
|
(9, 'P02PC04', 'User'),
|
||||||
|
(10, 'P02PC05', 'User');
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
@ -161,7 +178,29 @@ INSERT INTO `wyniki` (`id_wynik`, `quiz_nazwa`, `user_nazwa`, `l_pkt`) VALUES
|
|||||||
(14, 'quiz2', 'Pawel', 5),
|
(14, 'quiz2', 'Pawel', 5),
|
||||||
(15, 'quiz3', 'Karo', 6),
|
(15, 'quiz3', 'Karo', 6),
|
||||||
(16, 'quiz4', 'Anna', 3),
|
(16, 'quiz4', 'Anna', 3),
|
||||||
(17, 'quiz5', 'Jan', 1);
|
(17, 'quiz5', 'Jan', 1),
|
||||||
|
(18, 'quiz1', 'Anna', 3),
|
||||||
|
(19, 'quiz2', 'Anna', 2),
|
||||||
|
(20, 'quiz1', 'Przemek', 5),
|
||||||
|
(21, 'quiz1', 'Piotr', 5),
|
||||||
|
(22, 'quiz1', 'Annie', 1),
|
||||||
|
(23, 'quiz1', 'Zosia', 4),
|
||||||
|
(24, 'quiz1', 'Pawel', 3),
|
||||||
|
(25, 'quiz6', 'Adam', 5),
|
||||||
|
(26, 'quiz17', 'Adam', 1),
|
||||||
|
(27, 'quiz8', 'Adam', 3),
|
||||||
|
(28, 'quiz19', 'Adam', 3),
|
||||||
|
(29, 'quiz10', 'Adam', 4),
|
||||||
|
(30, 'quiz6', 'Pawel', 3),
|
||||||
|
(31, 'quiz17', 'Pawel', 2),
|
||||||
|
(32, 'quiz18', 'Pawel', 1),
|
||||||
|
(33, 'quiz4', 'Pawel', 5),
|
||||||
|
(34, 'quiz20', 'Pawel', 4),
|
||||||
|
(35, 'quiz6', 'Karo', 3),
|
||||||
|
(36, 'quiz17', 'Karo', 5),
|
||||||
|
(37, 'quiz3', 'Karo', 5),
|
||||||
|
(38, 'quiz4', 'Karo', 1),
|
||||||
|
(39, 'quiz10', 'Karo', 2);
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Indeksy dla zrzutów tabel
|
-- Indeksy dla zrzutów tabel
|
||||||
@ -205,31 +244,31 @@ ALTER TABLE `wyniki`
|
|||||||
-- AUTO_INCREMENT dla tabeli `pytania`
|
-- AUTO_INCREMENT dla tabeli `pytania`
|
||||||
--
|
--
|
||||||
ALTER TABLE `pytania`
|
ALTER TABLE `pytania`
|
||||||
MODIFY `id_pytania` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=44;
|
MODIFY `id_pytania` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=45;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- AUTO_INCREMENT dla tabeli `pytania_quiz`
|
-- AUTO_INCREMENT dla tabeli `pytania_quiz`
|
||||||
--
|
--
|
||||||
ALTER TABLE `pytania_quiz`
|
ALTER TABLE `pytania_quiz`
|
||||||
MODIFY `id_quiz_pytania` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
|
MODIFY `id_quiz_pytania` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- AUTO_INCREMENT dla tabeli `quiz`
|
-- AUTO_INCREMENT dla tabeli `quiz`
|
||||||
--
|
--
|
||||||
ALTER TABLE `quiz`
|
ALTER TABLE `quiz`
|
||||||
MODIFY `id_quizu` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;
|
MODIFY `id_quizu` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=36;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- AUTO_INCREMENT dla tabeli `users`
|
-- AUTO_INCREMENT dla tabeli `users`
|
||||||
--
|
--
|
||||||
ALTER TABLE `users`
|
ALTER TABLE `users`
|
||||||
MODIFY `id_user` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
|
MODIFY `id_user` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- AUTO_INCREMENT dla tabeli `wyniki`
|
-- AUTO_INCREMENT dla tabeli `wyniki`
|
||||||
--
|
--
|
||||||
ALTER TABLE `wyniki`
|
ALTER TABLE `wyniki`
|
||||||
MODIFY `id_wynik` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=18;
|
MODIFY `id_wynik` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=40;
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||||
|
Loading…
Reference in New Issue
Block a user