-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSingleplayer.py
128 lines (93 loc) · 4.71 KB
/
Singleplayer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import tkinter as tk
from tkinter import *
from tkinter.ttk import *
from PIL import ImageTk, Image
import csv
def open_singleplayer():
def close_and_signup():
sp.destroy()
from Signup import signup_window
signup_window()
sp = tk.Tk()
sp.title("Quicket-Singleplayer")
sp.resizable(False, False)
sp.configure(background='light grey')
p1 = tk.PhotoImage(file=r'images\home\quicket.png')
sp.iconphoto(True, p1)
def center_window(window, width, height):
# Get screen width and height
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
# Calculate x and y coordinates to center the window
x = (screen_width // 2) - (width // 2)
y = (screen_height // 2) - (height // 2)
# Set window size and position
window.geometry(f"{width}x{height}+{x}+{y}")
# Set window size and center it
window_width = 600
window_height = 900
center_window(sp, window_width, window_height)
sp.grid_columnconfigure(0, weight=1)
sp.grid_columnconfigure(1, weight=1)
sp.grid_columnconfigure(2, weight=1)
heading = Label(sp, text="Choose an account", font=('Times New Roman', 50, 'bold', 'underline'), background='light grey')
heading.grid(row=0, column=1, pady=30)
stadium = Image.open(r'images\singleplayer\stadium.png')
quicket_image_resized = stadium.resize((500,300))
quicket_resized = ImageTk.PhotoImage(quicket_image_resized)
quicket_image_label = Label(sp, image=quicket_resized)
quicket_image_label.grid(row=1, column=1)
name_var=tk.StringVar()
passw_var=tk.StringVar()
def submit():
username=name_var.get()
password=passw_var.get()
print("Username input: " + username)
print("Password input: " + password)
with open(r'all_data\user_data.csv', 'r') as passwords:
pass_reader = csv.reader(passwords, delimiter=',')
for row in pass_reader:
if len(row[1]) > 2:
if row[1] == username:
if row[2] == password:
print("correct password")
sp.destroy()
name = row[0]
from Singleplayer_start import start_match_singleplayer as start
start(name, username)
else:
print("wrong password")
tk.messagebox.showerror("Incorrect password", "Please try again")
return
user_pass_frame = tk.Frame(sp, background='light grey')
user_pass_frame.grid(row=2, column=1, pady =20)
name_label = tk.Label(user_pass_frame, text = 'Username:', font=('calibre',20, 'bold'), background='light grey')
name_label.grid(row=0, column=0)
usernames = []
with open(r'all_data\user_data.csv') as users:
user_reader = csv.reader(users, delimiter=',')
for row in user_reader:
if row[1] == 'username':
pass
else:
username = row[1]
usernames.append(username)
name_dropdown = Combobox(user_pass_frame, textvariable=name_var, values=usernames, state="readonly", font=('calibre',19,'bold'), background='light grey')
name_dropdown.grid(row=0, column=1)
passw_label = tk.Label(user_pass_frame, text = 'Password:', font = ('calibre',20,'bold'), background='light grey')
passw_label.grid(row=1, column=0)
passw_entry=tk.Entry(user_pass_frame, textvariable = passw_var, font = ('calibre',20,'normal'), show = '*')
passw_entry.grid(row=1, column=1)
login = tk.PhotoImage(file=r'images\singleplayer\login.png')
login_btn = login.subsample(5, 5)
login_button=tk.Button(user_pass_frame,image=login_btn, command = submit, borderwidth=0, background='light grey')
login_button.grid(row=2, column=1, pady= 10)
signup_frame = tk.Frame(sp, background='light grey')
signup_frame.grid(row=3, column=1, pady = 0)
login_option = tk.Label(signup_frame, text = 'Don\'t have an account?', font=('Times New Roman', 40, 'bold'), background='light grey')
login_option.grid(row=0, column=1, pady=0)
signup = tk.PhotoImage(file=r'images\singleplayer\signup.png')
signup_btn = signup.subsample(2, 2)
signup_button=tk.Button(signup_frame,image=signup_btn, command = close_and_signup, borderwidth=0, background='light grey')
signup_button.grid(row=1, column=1, pady=20)
sp.mainloop()