Question: Create an Python program using tkinter that does the following: 1) Create a main window widget 2) Create three frame widgets 3) Put a label

Create an Python program using tkinter that does the following:

1) Create a main window widget

2) Create three frame widgets

3) Put a label in each frame - use your own text

4) Put a button widget in each of the top two frames. Create a message box for each button. It is your choice what the message will say. Use your own text.

5) In the third frame, add a Quit button

Program one

import tkinter import tkinter.messagebox

class MyGUI: def __init__(self): # The main window widget is created. self.main_window = tkinter.Tk()

# There is a Button widget created. The text shown # 'Option 1'should appear on the face of the Button. # The do_something method should be executed when # the user clicks the Button. self.first_button = tkinter.Button(self.main_window, text='Option 1', command=self.do_something) # There is a Button widget created. The text shown # 'Option 2'should appear on the face of the Button. # The write_slogan method should be executed when # the user clicks the Button. self.other_button = tkinter.Button(self.main_window, text='Option 2', command=self.write_slogan)

# Quit button is created. When this button is clicked # the root widget's destroy method is called. # (The main_window variable references the root widget, # so the callback function is self.main_window.destroy.) self.quit_button = tkinter.Button(self.main_window, text='Quit', command=self.main_window.destroy)

# Pack the Buttons. self.first_button.pack() self.other_button.pack() self.quit_button.pack() # Enter the tkinter main loop. tkinter.mainloop()

# The do_something method is a callback function # for the Button widget. def do_something(self): # Dialog box shows the responds with the following info. tkinter.messagebox.showinfo('Happy Program', 'Option 1 button has been clicked.') # The write_slogan method is a callback function # for the Button widget. def write_slogan(self): # Dialog box shows the responds with the following info. tkinter.messagebox.showinfo('Happy Program', 'Its ok we speak Computer!') # Create an instance of the MyGUI class. my_gui = MyGUI()

Am I doing this correctly? I'm not sure.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!