The game of wordle! Note: enter a 5 letter word at the start or it will crash.
from kandinsky import fill_rect as rct,draw_string as txt from ion import keydown from time import sleep KEYS=[18,"a",19,"b",20,"c",21,"d",22,"e",23,"f",24,"g",25,"h",26,"i",27,"j",28,"k",29,"l",30,"m",31,"n",32,"o",33,"p",34,"q",36,"r",37,"s",38,"t",39,"u",40,"v",42,"w",43,"x",44,"y",45,"z"] WHT,GRY=(255,255,255),(200,200,200) def dinput(x,y): a="" l=0 while True: if keydown(17): a=a[:-1] l=17 elif keydown(52)and len(a)==5:return a else: for i in range(len(KEYS)/2): if keydown(KEYS[i*2]): a+=KEYS[i*2+1] l=KEYS[i*2] a=a[:5] for i in range(5): try:txt(a[i],x+20*i,y,WHT,GRY) except:txt(" ",x+20*i,y,WHT,GRY) while keydown(l):pass l=0 def game(): rct(110,60,100,120,GRY) for i in range(6):rct(i*20+109,60,2,120,(0,0,0)) for i in range(7):rct(109,i*20+59,102,2,(0,0,0)) txt("WORDLE",130,20) txt("By squarepoint",90,40) for i in range(6): txt("Try: "+str(i+1),220,70) while keydown(52):pass a=dinput(115,61+20*i) for j in range(5): if a[j]==WORD[j]:c=(0,200,0) elif a[j]in WORD:c=(200,200,0) else:c=(100,100,100) rct(111+20*j,61+20*i,18,18,c) txt(a[j],115+20*j,61+20*i,WHT,c) if a==WORD: txt("GG! You guessed the Wordle in",15,183) txt(str(i+1)+" tries!",120,203) break if not a==WORD: txt("You lost",120,183) txt("The Wordle was "+WORD,50,203) WORD=input("Enter word: ") game()