684 lines
22 KiB
Python
684 lines
22 KiB
Python
|
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()
|