-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordle.py
50 lines (38 loc) · 1.18 KB
/
wordle.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
import re
import tkinter as tk
from tkinter.scrolledtext import ScrolledText
def clear(*v):
vars[0].set('*****')
vars[1].set('')
vars[2].set('')
def refresh(*v):
s1 = vars[0].get().lower()
s2 = vars[1].get().lower()
s3 = vars[2].get().lower()
for c in ' _*?':
s1 = s1.replace(c, '[a-z]')
patt = re.compile(s1, re.I)
results = [w for w in words
if patt.fullmatch(w)
and all(c in w.lower() for c in s2)
and not any(c in w.lower() for c in s3)]
txt.delete('1.0', 'end')
txt.insert('1.0', '\n'.join(results))
patt = re.compile('[a-z]+', re.I)
with open('words.txt') as f:
words = [w for w in f.read().split('\n') if patt.fullmatch(w)]
top = tk.Tk()
top.title('Wordle Assistant')
top.resizable(0, 0)
vars = []
for i, name in enumerate(['Pattern', 'Include', 'Exclude']):
var = tk.StringVar()
var.trace('w', refresh)
vars.append(var)
tk.Label(top, text=name+':').grid(row=0, column=i*2)
tk.Entry(top, textvariable=var).grid(row=0, column=i*2+1)
txt = ScrolledText(top)
txt.grid(row=3, column=0, columnspan=6)
top.bind('<Escape>', clear)
vars[0].set('*****')
top.mainloop()