程序代写代做代考 Programming Exercise 3-1

Programming Exercise 3-1

Programming Exercise 13-2

import tkinter

class LatinTranslatorGUI:

def __init__(self):

# Create the main window

self.main_window = tkinter.Tk()

# Create two frames

self.top_frame = tkinter.Frame(self.main_window)

self.bottom_frame = tkinter.Frame(self.main_window)

# Create a blank label in the top frame

self.value = tkinter.StringVar()

self.word_label = tkinter.Label(self.top_frame, \

textvariable= self.value)

# Create the buttons in the bottom frame

self.sinister_button = tkinter.Button(self.bottom_frame, \

text = ‘sinister’, \

command = self.show_word1)

self.dexter_button = tkinter.Button(self.bottom_frame, \

text = ‘dexter’, \

command = self.show_word2)

self.medium_button = tkinter.Button(self.bottom_frame,

text = ‘medium’, \

command = self.show_word3)

# Pack the label

self.word_label.pack()

# Pack the buttons

self.sinister_button.pack(side = ‘left’)

self.dexter_button.pack(side = ‘left’)

self.medium_button.pack(side = ‘left’)

# Pack the frames

self.top_frame.pack()

self.bottom_frame.pack()

# Enter the tkinter main loop

tkinter.mainloop()

# Define the show_word functions

def show_word1(self):

self.value.set(‘left’)

def show_word2(self):

self.value.set(‘right’)

def show_word3(self):

self.value.set(‘center’)

# Create an instance of LatinTranslatorGUI

latin_translator = LatinTranslatorGUI()