Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
544 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Playing Wordle in Python |
---|
A modest Python program to mimic the popular online Wordle game, using a Tkinter form and some basic classes. |
Not to be outdone by my colleagues' impressive Wordle games in Excel VBA and Power BI, I thought I'd get Wordle working in Python.
I think the game works, but I haven't tested it exhaustively. The opportunity to share your results will be in version 2 of the software!
Here's what a typical screen looks like:
The word was DEMUR on this occasion, if you're wondering.
To make the game easy to run, I haven't used any external modules - just these:
The only modules used by this Wordle program.
I've also included all of the code in a single file, which you can download here. This also includes these two text files:
File | Contents |
---|---|
words.txt | A list of all the 12,973 valid five-letter words that you can guess in Wordle. |
targets.txt | A list of the 2,315 possible words you might have to guess. |
You'll need to set the path to where these files are on your computer at the start of the program wordle.py:
Make sure you change this file path.
You can run the program as normal in Python:
Click on the letters that you want to try. Use BACK to change a letter, and ENTER when you have a valid five-letter word.
Each time that you run the program it will pick a new random word from the appropriate text file.
The program uses TKinter for its graphical interface, a Python module I neither know particularly well nor love (this probably shows with the slightly clunky way I draw the buttons). I've used two classes:
Class | Used to |
---|---|
Button | Hold each of the letter buttons in the keyboard |
Letter | Used to hold each of the letters in the 6 rows at the top. |
I've also added a fair few additional properties/attributes to the TKinter.Tk fom class.
I had fun creating this, although suspect I haven't quite ironed out all of the bugs. Let me know your thoughts!
Some other pages relevant to the above blog include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.