SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Gui Programming
Exercise:
Programming Exercises
Question:1 | ISBN:9780132576376 | Edition: 2

Question

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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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:

1 0

Discussions

Post the discussion to improve the above solution.