Skip to content

Instantly share code, notes, and snippets.

@dominikbasista
Created March 28, 2018 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominikbasista/31ac69bcd9627ce0fc5ca8c6bcfbaca0 to your computer and use it in GitHub Desktop.
Save dominikbasista/31ac69bcd9627ce0fc5ca8c6bcfbaca0 to your computer and use it in GitHub Desktop.
from squanchyGame import MainWindow
import model
class Controler():
@staticmethod
def random_pol_word():
from squanchyGame import MainWindow
model.Model.random_pol_word()
a=model.Model.first_pol_word
MainWindow.show_window.configure(text=a)
@staticmethod
def random_eng_word():
model.Model.random_eng_word()
import random
#from squanchyGame import MainWindow
class Model:
@staticmethod
def random_pol_word():
conn = sqlite.connect('words.db')
cur = conn.cursor()
row_num=cur.execute(""" select count(*) from table1;""")
cur.execute("""SELECT * FROM table1 ORDER BY RANDOM() LIMIT 120;""")
sel_pol= cur.fetchall()
cur.execute("""SELECT weight FROM table1 ORDER BY RANDOM() LIMIT 120;""")
tuple_of_weigth = cur.fetchall()
list_of_weights =[]
for i in tuple_of_weigth:
list_of_weights.append(i[0])
all_random=random.choices(sel_pol,weights=list_of_weights)
first_pol_word=all_random[0][1]
#MainWindow.show_window.configure(text=first_pol_word)
print(all_random)
conn.commit()
conn.close()
option=str("polish")
@staticmethod
def random_eng_word():
conn = sqlite.connect('words.db')
cur = conn.cursor()
row_num = cur.execute(""" select count(*) from table1;""")
cur.execute("""SELECT * FROM table1 ORDER BY RANDOM() LIMIT 120;""")
sel_eng = cur.fetchall()
cur.execute("""SELECT weight FROM table1 ORDER BY RANDOM() LIMIT 120;""")
tuple_of_weigth = cur.fetchall()
list_of_weights = []
for i in tuple_of_weigth:
list_of_weights.append(i[0])
all_random = random.choices(sel_eng, weights=list_of_weights)
first_eng_word=all_random[0][5]
#MainWindow.show_window.configure(text=first_eng_word)
print(all_random)
conn.commit()
conn.close()
option=str("english")
import tkinter as tk
from tkinter import *
import sqlite3 as sqlite
import re
from controler import Controler
import logic
import random
from PIL import Image,ImageTk
conn = sqlite.connect('words.db')
cur = conn.cursor()
class MainWindow(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.master = master
self.master.geometry('725x350+300+200')
self.master.resizable(False,False)
self.menu = Menu(master)
self.master.config(menu=self.menu)
self.file = Menu(self.menu)
self.file.add_command(label="Dificultnes level")
self.file.add_command(label="New Game")
self.file.add_command(label="New User", command=lambda:logic.User.new_user_input())
self.file.add_command(label="Change User")
self.menu.add_cascade(label="File", menu=self.file)
self.exit = Menu(self.menu)
self.exit.add_command(label="Save and Exit")
self.menu.add_cascade(label="Exit", menu=self.exit)
self.pic_ang_to_pol = ImageTk.PhotoImage(Image.open("img/ang_to_pol.png"))
self.pic_pol_to_ang = ImageTk.PhotoImage(Image.open("img/pol_to_ang.png"))
self.random_eng_button = Button(master, text="Get a Word", width=130, height=49, bd=0, command=Controler.random_eng_word)
self.random_eng_button.config(image=self.pic_ang_to_pol)
self.random_eng_button.place(x=195, y=30)
self.random_button_2 = Button(master, text="Get a Word", width=130, height=49, bd=0, command = Controler.random_pol_word)
self.random_button_2.config(image=self.pic_pol_to_ang)
self.random_button_2.place(x=395, y=30)
self.show_window = Label(master, width=24, justify=CENTER, highlightbackground="#ffa500",highlightthickness=3,font=("Lobster",16))
self.show_window.config(highlightbackground="#ffa500")
self.show_window.place(x=220, y=100)
self.answer=Entry(master, width=24, justify=CENTER, bd=0, highlightbackground="#ffa500", highlightthickness=3,font=("Lobster",16))
self.answer.config(highlightbackground="#ffa500")
self.answer.place(x=220, y=155)
self.check_button = Button(master, text="Check", width=4, height=1, bg="#ffa500", fg="#00247d", bd=0,activebackground="#ffa500", activeforeground="#00247d", font=("Lobster", 21), command=self.check)
self.check_button.place(x=220, y=210)
self.omit_button = Button(master, text="Omit", width=4, height=1, bg="#ffa500", fg="#00247d", bd=0 ,activebackground="#ffa500", activeforeground="#00247d", font=("Lobster", 21), command=self.check)
self.omit_button.place(x=335, y=210)
self.status_label = Label(master, height=50, width=50, bg='#7793d4')
self.status_label.place(x=460, y=205)
self.hint_img = ImageTk.PhotoImage(Image.open("img/hint.png"))
self.hint_button=Button(height=55,width=55,bg="#ffa500",image=self.hint_img)
self.hint_button.pack(anchor=NE)
self.exit_img = ImageTk.PhotoImage(Image.open("img/exit.png"))
self.exit_button = Button(height=55, width=55, bg="#2a3693",image=self.exit_img, command=lambda: logic.Exit.save_and_exit())
self.exit_button.pack(anchor=NE)
self.no_idea_img = ImageTk.PhotoImage(Image.open("img/no_idea.png"))
self.no_idea_button = Button(height=55, width=55, bg="#2a3693", image=self.no_idea_img)
self.no_idea_button.pack(anchor=NE)
self.change_user_img = ImageTk.PhotoImage(Image.open("img/change_user.png"))
self.change_user_button = Button(master,height=55, width=55, image=self.change_user_img)
self.change_user_button.place(x=0,y=0)
self.add_word_img = ImageTk.PhotoImage(Image.open("img/add_word.png"))
self.add_word_button = Button(height=55, width=55, image=self.add_word_img, command=self.window_popup)
self.add_word_button.place(x=0,y=55)
self.statistic_img = ImageTk.PhotoImage(Image.open("img/statistic.png"))
self.hint3_button = Button(height=55, width=55, image=self.statistic_img)
self.hint3_button.place(x=0,y=110)
self.user = Label(master,text="Score: ",height=1,width=15,justify=LEFT, font=("Helvetica",10,"bold"))
self.user.place(x=1, y=330)
self.points=Label(master,text="Points: ",height=1,width=15,justify=LEFT, font=("Helvetica",10,"bold"))
self.points.place(x=615, y=330)
def random_eng_word(self):
self.conn = sqlite.connect('words.db')
self.cur = conn.cursor()
self.row_num = cur.execute(""" select count(*) from table1;""")
self.cur.execute("""SELECT * FROM table1 ORDER BY RANDOM() LIMIT 120;""")
self.sel_eng = self.cur.fetchall()
self.cur.execute("""SELECT weight FROM table1 ORDER BY RANDOM() LIMIT 120;""")
self.tuple_of_weigth = self.cur.fetchall()
self.list_of_weights = []
for i in self.tuple_of_weigth:
self.list_of_weights.append(i[0])
self.all_random = random.choices(self.sel_eng, weights=self.list_of_weights)
self.first_eng_word=self.all_random[0][5]
self.show_window.configure(text=self.first_eng_word)
print(self.all_random)
self.conn.commit()
self.conn.close()
self.option=str("english")
def check(self):
if self.option=="polish":
if self.answer.get()==self.all_random[0][5] or self.all_random[0][6] or self.all_random[0][7] or self.all_random[0][8]:
self.corect_img = ImageTk.PhotoImage(Image.open("img/corect.png"))
self.status_label = Label(root, height=50, width=50, bg='#7793d4')
self.status_label.place(x=460, y=205)
self.status_label.config(image=self.corect_img)
self.answer.delete(0, END)
self.show_window.config(text="")
self.status_label.after(3000, lambda: self.status_label.destroy())
print("dobre0")
else:
self.incorect_img = ImageTk.PhotoImage(Image.open("img/incorect1.png"))
self.status_label = Label(root, height=50, width=50, bg='#7793d4')
self.status_label.place(x=460, y=205)
self.status_label.config(image=self.incorect_img)
self.answer.delete(0, END)
self.status_label.after(3000, lambda: self.status_label.destroy())
print("zle0")
elif self.option == "english":
if self.answer.get()==self.all_random[0][1] or self.all_random[0][2] or self.all_random[0][3] or self.all_random[0][4]:
self.corect_img = ImageTk.PhotoImage(Image.open("img/corect.png"))
self.status_label = Label(root, height=50, width=50, bg='#7793d4')
self.status_label.place(x=460, y=205)
self.status_label.config(image=self.corect_img)
self.answer.delete(0, END)
self.show_window.config(text="")
self.status_label.after(3000, lambda: self.status_label.destroy())
print("dobre1")
#self.status_label.destroy()
else:
self.incorect_img = ImageTk.PhotoImage(Image.open("img/incorect1.png"))
self.status_label = Label(root, height=50, width=50, bg='#7793d4')
self.status_label.place(x=460, y=205)
self.status_label.config(image=self.incorect_img)
self.answer.delete(0, END)
self.status_label.after(3000, lambda: self.status_label.destroy())
def window_popup(self):
self.top = Toplevel(bg="#7793d4")
self.label_1 = Label(self.top, text="Insert 1st English meaning", font=("Lobster", 11), bg="#7793d4")
self.label_1.grid(row=0,column=1)
self.entry_1 = Entry(self.top,highlightbackground="#ffa500",highlightthickness=2)
self.entry_1.delete(0, END)
self.entry_1.grid(row=1, column=1, pady=4)
self.firstEn = self.entry_1.get()
self.label_2 = tk.Label(self.top, text="2nd English meaning",font=("Lobster", 11), bg="#7793d4")
self.label_2.grid(row=2, column=1)
self.entry_2 = tk.Entry(self.top,highlightbackground="#ffa500",highlightthickness=2,font=("Lobster", 11))
self.entry_2.grid(row=3, column=1)
self.secondEn = self.entry_2.get()
self.label_3 = tk.Label(self.top, text="Insert 3rd Eenglish meaning",font=("Lobster", 11), bg="#7793d4")
self.label_3.grid(row=4, column=1)
self.entry_3 = tk.Entry(self.top,highlightbackground="#ffa500",highlightthickness=2,font=("Lobster", 11))
self.entry_3.grid(row=5, column=1)
self.thirdEn = self.entry_3.get()
self.label_4 = tk.Label(self.top, text="Insert 4th English meaning",font=("Lobster", 11), bg="#7793d4")
self.label_4.grid(row=6, column=1)
self.entry_4 = tk.Entry(self.top,highlightbackground="#ffa500",highlightthickness=2,font=("Lobster", 11))
self.entry_4.grid(row=7, column=1)
self.fourthEn = self.entry_4.get()
self.label_5 = tk.Label(self.top, text="Insert 1th Polish meaning",font=("Lobster", 11), bg="#7793d4")
self.label_5.grid(row=8, column=1)
self.entry_5 = tk.Entry(self.top,highlightbackground="#ffa500",highlightthickness=2,font=("Lobster", 11))
self.entry_5.grid(row=9, column=1)
self.firstPl = self.entry_5.get()
self.label_6 = tk.Label(self.top, text="Insert 2nd Polish meaning",font=("Lobster", 11), bg="#7793d4")
self.label_6.grid(row=10, column=1)
self.entry_6 = tk.Entry(self.top,highlightbackground="#ffa500",highlightthickness=2,font=("Lobster", 11))
self.entry_6.grid(row=11, column=1)
self.secondPl = self.entry_6.get()
self.label_7 = tk.Label(self.top, text="Insert 3rd Polish meaning",font=("Lobster", 11), bg="#7793d4")
self.label_7.grid(row=12, column=1)
self.entry_7 = tk.Entry(self.top,highlightbackground="#ffa500",highlightthickness=2,font=("Lobster", 11))
self.entry_7.grid(row=13, column=1)
self.thirdPl = self.entry_7.get()
self.label_8 = tk.Label(self.top, text="Insert 4th Polish meaning",font=("Lobster", 11), bg="#7793d4")
self.label_8.grid(row=14, column=1)
self.entry_8 = tk.Entry(self.top,highlightbackground="#ffa500",highlightthickness=2,font=("Lobster", 11))
self.entry_8.grid(row=15, column=1)
self.fourthPl = self.entry_8.get()
self.add_button = Button(self.top, text="Add", font=("Lobster", 11, "bold"), bd=0, bg="#ffa500", command=self.add_words)
self.add_button.config(command=lambda:logic.Speling.spelingChecker(self.entry_1.get(),self.entry_2,self.entry_3,self.entry_4))
self.add_button.grid(row=16, column=1)
return self.top
def add_words(self):
self.en1_add_to_db = self.entry_1.get()
self.entry_1.delete(0,END)
self.en2_add_to_db = self.entry_2.get()
self.entry_2.delete(0, END)
self.en3_add_to_db = self.entry_3.get()
self.entry_3.delete(0, END)
self.en4_add_to_db = self.entry_4.get()
self.entry_4.delete(0, END)
self.pl1_add_to_db = self.entry_5.get()
self.entry_5.delete(0, END)
self.pl2_add_to_db = self.entry_6.get()
self.entry_6.delete(0, END)
self.pl3_add_to_db = self.entry_7.get()
self.entry_7.delete(0, END)
self.pl4_add_to_db = self.entry_8.get()
self.entry_8.delete(0, END)
list_of_fields=[self.en1_add_to_db, self.en2_add_to_db, self.en3_add_to_db, self.en4_add_to_db,
self.pl1_add_to_db, self.pl2_add_to_db, self.pl3_add_to_db, self.pl4_add_to_db]
cur.execute("""INSERT INTO table1(english_word, english_word_1, english_word_2, english_word_3,
polish_word, polish_word_1, polish_word_2, polish_word_3) VALUES(?,?,?,?,?,?,?,?)""",list_of_fields)
conn.commit()
root = Tk()
app = MainWindow(root)
app.master.title("Squanchy Game")
app.master.configure(background='#7793d4')
app.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment