- CodeCraft by Dr. Christine Lee
- Posts
- Create Easy AI Systems with PySimpleGUI! ๐ค๐
Create Easy AI Systems with PySimpleGUI! ๐ค๐
AI Made Fun

RGB AI-based Expert System
Introduction
Hello, CodeCrafters! ๐
Today, weโre diving into the exciting world of AI-based expert systems, and weโre going to make it fun and easy with PySimpleGUI.
Expert systems are a type of AI that simulate the decision-making ability of a human expert.
We'll build a simple expert system that gives advice based on user input.
Ready? Letโs get started! ๐
Don't Miss This Workshop! ๐
Before we dive in, we have an exciting opportunity for you! Don't miss out on the chance to elevate your AI game by attending the "Learn the 20 Most Insane AI Tools on the Internet" workshop.
Learn AI Strategies worth a Million Dollar in this 3 hour AI Workshop. Join now for $0
Everyone tells you to learn AI but no one tells you where.
We have partnered with GrowthSchool to bring this ChatGTP & AI Workshop to our readers. It is usually $199, but free for you because you are our loyal readers ๐
This workshop has been taken by 1 Million people across the globe, who have been able to:
Build business that make $10,000 by just using AI tools
Make quick & smarter decisions using AI-led data insights
Write emails, content & more in seconds using AI
Solve complex problems, research 10x faster & save 16 hours every week
Youโll wish you knew about this FREE AI Training sooner (Btw, itโs rated at 9.8/10 โญ)
Now, back to our AI-based Expert Systemโฆ
Step-by-Step Tutorial
Step 1: Import the Required Libraries
First, letโs import PySimpleGUI and set up our layout.
import PySimpleGUI as sg
# Define the layout
layout = [
[sg.Text('Welcome to the AI Expert System!')],
[sg.Text('What is your favorite color?'), sg.InputText()],
[sg.Button('Submit'), sg.Button('Exit')]
]
# Create the window
window = sg.Window('AI Expert System', layout)
Step 2: Create the Event Loop
Next, weโll create an event loop to handle user interactions.
while True:
event, values = window.read()
if event sg.WINDOW_CLOSED or event 'Exit':
break
if event == 'Submit':
color = values[0].lower()
advice = get_advice(color)
sg.Popup(f'Based on your favorite color, here is some advice: {advice}')
window.close()
Step 3: Define the Expert System Logic
Now, let's define the get_advice function to provide advice based on the user's favorite color.
def get_advice(color):
if color == 'red':
return 'You are bold and courageous!'
elif color == 'blue':
return 'You are calm and trustworthy.'
elif color == 'green':
return 'You are balanced and nature-loving.'
else:
return 'You have a unique personality!'

Putting It All Together
Hereโs the complete code:
import PySimpleGUI as sg
def get_advice(color):
if color == 'red':
return 'You are bold and courageous!'
elif color == 'blue':
return 'You are calm and trustworthy.'
elif color == 'green':
return 'You are balanced and nature-loving.'
else:
return 'You have a unique personality!'
layout = [
[sg.Text('Welcome to the AI Expert System!')],
[sg.Text('What is your favorite color?'), sg.InputText()],
[sg.Button('Submit'), sg.Button('Exit')]
]
window = sg.Window('AI Expert System', layout)
while True:
event, values = window.read()
if event sg.WINDOW_CLOSED or event 'Exit':
break
if event == 'Submit':
color = values[0].lower()
advice = get_advice(color)
sg.Popup(f'Based on your favorite color, here is some advice: {advice}')
window.close()
Explanation
Layout Definition: We define the layout of our GUI with a text prompt, input box, and buttons.
Event Loop: We handle the events (button clicks) and read user input.
Expert System Logic: The
get_advicefunction provides personalized advice based on the user's favorite color.
Output



Have Fun with Your Expert System!
And there you have it! A simple and fun AI-based expert system using PySimpleGUI. You can expand this system by adding more questions and more complex advice logic. Enjoy experimenting and making it your own! ๐๐
Explore More Fun and Easy Expert Systems! ๐
Now that you've created your first AI-based expert system, the possibilities are endless!
Why not try building an expert system to recommend movies based on user preferences, suggest vacation destinations based on weather and activities, or even a system that offers personalized workout plans?
Each of these projects can be as simple or complex as you want, allowing you to flex your creativity while enhancing your programming skills.
Dive in and experiment with different ideasโyou'll be amazed at what you can achieve with PySimpleGUI and a bit of imagination. ๐๐ฌ๐ด๐๏ธโโ๏ธ
Letโs Inspire Future AI Coders Together! โ
Iโm excited to continue sharing my passion for Python programming and AI with you all. If youโve enjoyed the content and found it helpful, do consider supporting my work with a small gift. Just click the link below to make a difference โ itโs quick, easy, and every bit helps and motivates me to keep creating awesome contents for you.
Thank you for being amazing!
Ready for More Python Fun? ๐ฌ
Subscribe to our newsletter now and get a free Python cheat sheet! ๐ Dive deeper into Python programming with more exciting projects and tutorials designed just for beginners.
Keep learning, keep coding ๐ฉโ๐ป๐จโ๐ป, and keep discovering new possibilities! ๐ปโจ
Enjoy your journey into artificial intelligence, machine learning, data analytics, data science and more with Python!
Stay tuned for our next exciting project in the following edition!
Happy coding!๐๐โจ

