Experiment : 05
Title : Creating GUI with python containing widgets such as labels,
textbox, radio, checkboxes and custom dialog boxes.
Program:
import tkinter as tk
from tkinter import messagebox
Aim : Create a new window
root = tk.Tk()
Aim : Set the title of the window
root.title("My GUI")
Aim : Create a label widget
label = tk.Label(root, text="Welcome to my GUI!")
label.pack()
Aim : Create a textbox widget
textbox = tk.Entry(root)
textbox.pack()
Aim : Create a radio button widget
radio = tk.Radiobutton(root, text="Option 1",
value=1) radio.pack()
radio2 = tk.Radiobutton(root, text="Option 2",
value=2) radio2.pack()
Aim : Create a checkbox widget
checkbox = tk.Checkbutton(root, text="Check me!")
checkbox.pack()
Aim : Create a custom dialog box
def showDialog():
messagebox.showinfo("Message", "Hello World!")
button = tk.Button(root, text="Click me",
command=showDialog)
button.pack()
Aim : Start the main loop of the window
root.mainloop()
Output:
Conclusion: We have written basic program to create a basic GUI