Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Wordle.py
- from tkinter import *
- from tkinter import messagebox
- import random
- words = '''
- ABOUT ABOVE ABUSE ACTOR ADAPT ADDED ADMIT ADOPT ADULT AFTER AGAIN AGENT AGREE AHEAD AISLE ALARM ALBUM ALIEN ALIKE ALIVE ALLEY ALLOW ALONE ALONG ALOUD ALTER AMONG ANGEL ANGER ANGLE ANGRY ANKLE APART APPLE APPLY ARENA ARGUE ARISE ARMED ARRAY ARROW ASIDE ASSET AVOID AWAIT AWAKE AWARD AWARE AWFUL BADLY BASIC BASIS BEACH BEARD BEAST BEGIN BEING BELLY BELOW BENCH BIRTH BLACK BLADE BLAME BLANK BLAST BLEND BLESS BLIND BLINK BLOCK BLOND BLOOD BOARD BOAST BONUS BOOST BOOTH BRAIN BRAKE BRAND BRAVE BREAD BREAK BRICK BRIDE BRIEF BRING BROAD BROWN BRUSH BUDDY BUILD BUNCH BURST BUYER CABIN CABLE CANDY CARGO CARRY CARVE CATCH CAUSE CEASE CHAIN CHAIR CHAOS CHARM CHART CHASE CHEAP CHEAT CHECK CHEEK CHEER CHEST CHIEF CHILD CHILL CHUNK CIVIC CIVIL CLAIM CLASS CLEAN CLEAR CLERK CLICK CLIFF CLIMB CLING CLOCK CLOSE CLOTH CLOUD COACH COAST COLOR COUCH COULD COUNT COURT COVER CRACK CRAFT CRASH CRAWL CRAZY CREAM CRIME CROSS CROWD CROWN CRUEL CRUSH CURVE CYCLE DAILY DANCE DEATH DEBUT DELAY DENSE DEPTH DEVIL DIARY DIRTY DITTO DONOR DOUBT DOUGH DOZEN DRAFT DRAIN DRAMA DREAM DRESS DRIED DRIFT DRILL DRINK DRIVE DROWN DRUNK DYING EAGER EARLY EARTH EIGHT ELBOW ELDER ELECT ELITE EMPTY ENACT ENEMY ENJOY ENTER ENTRY EQUAL EQUIP ERROR ESSAY EVENT EVERY EXACT EXIST EXTRA FAINT FAITH FALSE FATAL FAULT FAVOR FENCE FEVER FEWER FIBER FIELD FIFTH FIFTY FIGHT FINAL FIRST FIXED FLAME FLASH FLEET FLESH FLOAT FLOOD FLOOR FLOUR FLUID FOCUS FORCE FORTE FORTH FORTY FORUM FOUND FRAME FRAUD FRESH FRONT FROWN FRUIT FULLY FUNNY GENRE GHOST GIANT GIVEN GLASS GLOBE GLORY GLOVE GRACE GRADE GRAIN GRAND GRANT GRAPE GRASP GRASS GRAVE GREAT GREEN GREET GRIEF GROSS GROUP GUARD GUESS GUEST GUIDE GUILT HABIT HAPPY HARSH HEART HEAVY HELLO HENCE HONEY HONOR HORSE HOTEL HOUSE HUMAN HUMOR HURRY IDEAL IMAGE IMPLY INDEX INNER INPUT IRONY ISSUE JEANS JOINT JUDGE JUICE JUROR KNEEL KNIFE KNOCK KNOWN LABEL LABOR LARGE LASER LATER LAUGH LAYER LEARN LEAST LEAVE LEGAL LEMON LEVEL LIGHT LIMIT LIVER LOBBY LOCAL LOGIC LOOSE LOVER LOWER LOYAL LUCKY LUNCH MAGIC MAJOR MAKER MARCH MARRY MATCH MAYBE MAYOR MEANS MEDAL MEDIA MERIT METAL METER MIDST MIGHT MINOR MINUS MIXED MODEL MONEY MONTH MORAL MOTOR MOUNT MOUSE MOUTH MOVIE MUSIC NAKED NASTY NAVAL NERVE NEVER NEWLY NIGHT NOISE NORTH NOVEL NURSE OCCUR OCEAN OFFER OFTEN ONION OPERA ORBIT ORDER ORGAN OTHER OUGHT OUTER OWNER PAINT PANEL PANIC PANTS PAPER PARTY PASTA PATCH PAUSE PEACE PHASE PHONE PHOTO PIANO PIECE PILOT PITCH PIZZA PLACE PLAIN PLANE PLANT PLATE PLEAD POINT PORCH POUND POWER PRESS PRICE PRIDE PRIME PRINT PRIOR PRIZE PROOF PROUD PROVE PULSE PUNCH PURSE QUEEN QUEST QUICK QUIET QUITE QUOTE RADAR RADIO RAISE RALLY RANCH RANGE RAPID RATIO REACH REACT READY REALM REBEL REFER RELAX REPLY RIDER RIDGE RIFLE RIGHT RISKY RIVAL RIVER ROBOT ROUGH ROUND ROUTE ROYAL RUMOR RURAL SADLY SALAD SALES SAUCE SCALE SCARE SCARY SCENE SCENT SCOPE SCORE SCREW SEIZE SENSE SERVE SEVEN SHADE SHAKE SHALL SHAME SHAPE SHARE SHARK SHARP SHEEP SHEER SHEET SHELF SHELL SHIFT SHINE SHIRT SHOCK SHOOT SHORE SHORT SHOUT SHOVE SHRUG SIGHT SILLY SINCE SIXTH SKILL SKIRT SKULL SLASH SLAVE SLEEP SLICE SLIDE SLOPE SMALL SMART SMELL SMILE SMOKE SNAKE SNEAK SOLAR SOLID SOLVE SORRY SOUND SOUTH SPACE SPARE SPARK SPEAK SPEED SPELL SPEND SPILL SPINE SPITE SPLIT SPOON SPORT SPRAY SQUAD STACK STAFF STAGE STAIR STAKE STAND STARE START STATE STEAK STEAL STEAM STEEL STEEP STEER STICK STIFF STILL STOCK STONE STORE STORM STORY STOVE STRAW STRIP STUDY STUFF STYLE SUGAR SUITE SUNNY SUPER SWEAR SWEAT SWEEP SWEET SWELL SWING SWORD TABLE TALLY TASTE TEACH TERMS THANK THEIR THEME THERE THESE THICK THIGH THING THINK THIRD THOSE THREE THROW THUMB TIGHT TIRED TITLE TODAY TOOTH TOPIC TOTAL TOUCH TOUGH TOWEL TOWER TOXIC TRACE TRACK TRADE TRAIL TRAIN TRAIT TRASH TREAT TREND TRIAL TRIBE TRICK TROOP TRUCK TRULY TRUNK TRUST TRUTH TUMOR TWICE TWIST UNCLE UNDER UNION UNITE UNITY UNTIL UPPER UPSET URBAN USUAL UTTER VAGUE VALID VALUE VIDEO VIRUS VISIT VITAL VOCAL VOICE VOTER WAGON WAIST WASTE WATCH WATER WEAVE WEIGH WEIRD WHALE WHEAT WHEEL WHERE WHICH WHILE WHITE WHOLE WHOSE WIDOW WOMAN WORKS WORLD WORRY WORTH WOULD WOUND WRIST WRITE WRONG YIELD YOUNG YOURS YOUTH'''.upper().split()
- def get_word():
- return random.choice(words)
- root = Tk()
- root.geometry("336x420+5+5")
- GREEN = "#007d21"
- YELLOW = "#e2e600"
- BLACK = "#000000"
- WHITE = "#FFFFFF"
- RED = "#8b0000"
- root.config(bg='grey30')
- def to_uppercase(*args):
- var.set(var.get().upper().strip()[:5])
- def reset():
- global word
- global guessnum
- guessnum = 0
- word = get_word()
- def init_board():
- for i in range(5):
- for j in range(1,6):
- label = Label(root, bg='grey30', font=("Arial", 29), width=2, borderwidth=2, relief=GROOVE)
- label.grid(row=j, column=i, pady=5)
- top_frame = Frame(root)
- top_frame.grid(row=0, column=0, padx=8, pady=5, columnspan=5)
- var = StringVar(top_frame)
- wordInput = Entry(top_frame, font=("Arial", 25), textvariable=var, width=12, justify='center')
- wordInput.grid(row=0, column=0, columnspan=4, sticky=NSEW)
- var.trace_add('write', to_uppercase)
- def getGuess():
- global word
- global guessnum
- guess = var.get().upper()
- guessnum += 1
- for i in range(5):
- label = Label(root, bg='grey20', font=("Arial", 29), width=2)
- label.grid(row=guessnum, column=i, pady=5)
- if len(guess) == 5:
- if guess in words:
- if word == guess: # CORRECT
- for i, letter in enumerate(guess):
- label = Label(root, text=letter.upper(), font=("Arial", 29), width=2)
- label.grid(row=guessnum, column=i, pady=5)
- label.config(bg=GREEN, fg=BLACK)
- messagebox.showinfo("CORRECT!", f"THE WORD WAS {word}")
- reset()
- else: # INCORRECT
- for i, letter in enumerate(guess):
- label = Label(root, text=letter.upper(), font=("Arial", 29), width=2)
- label.grid(row=guessnum, column=i, pady=5)
- if letter == word[i]: # if they get the letter right
- label.config(bg=GREEN, fg=BLACK)
- elif letter in word and not letter == word[i]: # if the letter is in the word, but not in the right spot
- label.config(bg=YELLOW, fg=BLACK)
- elif letter not in word:
- label.config(bg=BLACK, fg=WHITE)
- else:
- messagebox.showerror("SORRY...", "NOT A VALID ENTRY IN THIS WORDLE VERSION")
- else:
- messagebox.showerror("INVALID ENTRY", "PLEASE USE 5 CHARACTERS IN YOUR GUESS")
- if guessnum > 4 and word != guess:
- for i, letter in enumerate(word):
- label = Label(root, text=letter.upper(), font=("Arial", 29), width=2)
- label.grid(row=5, column=i, pady=5)
- label.config(bg=RED, fg=WHITE)
- messagebox.showerror("YOU LOSE!", f"THE WORD WAS {word}")
- reset()
- wordInput.focus_force()
- var.set('')
- if not guessnum:
- init_board()
- 0
- guessnum = 0
- reset()
- init_board()
- wordGuessButton = Button(top_frame, text="GUESS", font=("Arial", 17), bg=GREEN, fg=WHITE, command=getGuess)
- wordGuessButton.grid(row=0, column=4)
- root.bind('<Return>', lambda self: getGuess())
- wordInput.focus_force()
- root.mainloop()
Add Comment
Please, Sign In to add comment