Name and Address
Write a GUI program that displays your name and address when a button is clicked. The program’s window should appear as the sketch on the left side of Figure 14-26 when it runs. When the user clicks the Show Info button, the program should display your name and address, as shown in the sketch on the right of the figure.
Program:
# import tkinter for GUI
import tkinter as tk
def display_info():
name = "Steven Marcus"
address = "274 Baily Drive \n Waynesville, NC 27999"
info_label.config(text=f"{name}\n{address}")
# Create the main window
window = tk.Tk()
window.title("Personal Information")
window.geometry("300x150")
# Create a label to display the information
info_label = tk.Label(window, font=("Arial", 12), justify=tk.CENTER)
info_label.pack(pady=20)
# Create a button to show the information
show_info_button = tk.Button(window, text="Show Info", command=display_info)
show_info_button.place(x=80, y=100)
# Create a button to quit the window
quit_button = tk.Button(window, text="Quit", command=quit)
quit_button.place(x=180, y=100)
# Start the main event loop
window.mainloop()
Ouput1:
Ouput2: