Human Computer Interaction &
Computer Graphics Lab Manual
Lab 1: Setting up Development Environment for GUI and Graphics
Programming
Objective
To install and configure Python with required libraries and create a simple GUI program to
ensure everything works.
Theory
Human-Computer Interaction (HCI) involves creating user interfaces that people can
interact with. In this lab, we set up Python and the libraries (tkinter for GUI, pygame for
graphics, and matplotlib for visualization). A first 'Hello World' GUI program helps students
confirm the setup.
Requirements
• Python 3.10+ installed
• Libraries: pygame, matplotlib, PyOpenGL
• IDE: PyCharm / VS Code / IDLE
Procedure
1. Open your IDE (VS Code or PyCharm).
2. Install required libraries:
pip install pygame matplotlib pyopengl
3. Create a new Python file named lab1_hello_gui.py.
4. Write and run the following code in part a.
5. Execute code line by line
a)
# Import tkinter library
import tkinter as tk
# Create main window
root = tk.Tk()
root.title("Hello HCI Lab")
root.geometry("400x200")
# Add a label
label = tk.Label(root, text="Welcome to HCI Lab!", font=("Arial", 16))
label.pack(pady=40)
# Add a quit button
quit_btn = tk.Button(root, text="Exit", command=root.destroy)
quit_btn.pack(pady=10)
root.mainloop()
Explanation of Code
- tk.Tk() creates the main application window.
- .title() sets the title of the window.
- .geometry() defines size.
- pady adds vertical space for text
- Label displays text.
- Button adds interactivity.
Expected Output
A window appears with the title 'Hello HCI Lab', a welcome message, and a button to exit.
Experiment Variation
- Change window size to 400x100.
- Add Another Label between first label and exit.
- Change ‘pady’ where it is
Procedure
1. Create a copy of old Python file named lab1_hello_button_gui.py.
2. Write and run the following code in part b.
3. Execute code line by line
b)
# Import tkinter library
import tkinter as tk
# Create main window
root = tk.Tk()
root.title("Hello HCI Lab")
root.geometry("400x200")
# Add a label
label = tk.Label(root, text="Welcome to HCI Lab!", font=("Arial", 16))
label.pack(pady=20)
# Function to update text when button is clicked
def update_text():
label.config(text="Button was clicked!")
# Add a button
btn = tk.Button(root, text="Click Me", command=update_text)
btn.pack(pady=10)
# Add a quit button
quit_btn = tk.Button(root, text="Exit", command=root.destroy)
quit_btn.pack(pady=10)
root.mainloop()
Expected Output
A window appears with the title 'Hello HCI Lab', a welcome message, a button to Click me
and a button to exit.
Experiment Variation
- Change window size to 400x100.
- Add Another button with different text
- Change ‘pady’ where it is
Viva Questions
1. What is the purpose of tkinter in Python?
2. What does root.mainloop() do?
3. Why is it important to test environment setup before continuing with other labs?