Question

In: Computer Science

Using Python Look at the following list of Spanish words and their meanings. Spanish English uno...

Using Python

Look at the following list of Spanish words and their meanings.

Spanish English

uno one

dos two

tres three

Write a GUI program that translates the Spanish words to English. The window should have three buttons, one for each Spanish word. When the user clicks a button, the program displays the English translation in a label.

Solutions

Expert Solution

Python code for the given problem statement is as follows:

(Appropriate Comments are given as and when necessary for your easy understanding)

from tkinter import *
def clear_all() :  
    translate_field.delete(0, END) 
    # set focus on the translate_field entry box   
    translate_field.focus_set()  

def translate1():  
    translate_field.insert(10,"One") 
def translate2():  
    translate_field.insert(10,"Two") 
def translate3():  
    translate_field.insert(10,"Three") 

root = Tk()  
    
# Set the background colour of GUI window  
root.configure(background = 'light green')  
    
# Set the configuration of GUI window  
root.geometry("400x250")  
    
# set the name of tkinter GUI window  
root.title("Translate")   
        
# Create a English Translation : label  
label1 = Label(root, text = "English Translation : ",fg = 'black', bg = 'red')  
  
# grid method is used for placing   
# the widgets at respective positions   
# in table like structure . 
  
# padx keyword argument used to set paading along x-axis . 
# pady keyword argument used to set paading along y-axis .  
label1.grid(row = 1, column = 0, padx = 10, pady = 10)   
  
# Create a text box   
# for output of translated information 
translate_field = Entry(root)   
    
translate_field.grid(row = 1, column = 1, padx = 10, pady = 10)   

button1 = Button(root, text = "Uno", bg = "red",fg = "black", command = translate1)  
button2 = Button(root, text = "Dos", bg = "red",fg = "black", command = translate2)  
button3 = Button(root, text = "Tres", bg = "red",fg = "black", command = translate3)    
# Create a Clear Button and attached   
# to clear_all function   
button4 = Button(root, text = "Clear", bg = "cyan",fg = "black", command = clear_all) 
    
button1.grid(row = 4, column = 1, pady = 10)  
button2.grid(row = 6, column = 1, pady = 10) 
button3.grid(row = 8, column = 1, pady = 10) 
button4.grid(row = 10, column = 1, pady = 10) 
  
# Start the GUI   
root.mainloop() 

Output:

I hope you find the solution helpful and insightful.

Keep Learning !


Related Solutions

A student studying for a vocabulary test knows the meanings of 12 words from a list...
A student studying for a vocabulary test knows the meanings of 12 words from a list of 22 words. If the test contains 10 words from the study list, what is the probability that at least 8 of the words on the test are words that the student knows? (Round your answer to three decimal places.)
A student studying for a vocabulary test knows the meanings of 10 words from a list...
A student studying for a vocabulary test knows the meanings of 10 words from a list of 26 words. If the test contains 10 words from the study list, what is the probability that at least 8 of the words on the test are words that the student knows? (Round your answer to three decimal places.)
python Create a dictionary and insert several English words as keys and the Pig Latin (or...
python Create a dictionary and insert several English words as keys and the Pig Latin (or any other language) translations as values. Write a function called bonus that takes as a parameter a dictionary that has names as keys and salaries as values. Your function should increase everyone’s salary in the dictionary by 5%. Write a function called updateAge that takes as parameters a list of names of people whose birthday it is today, and a dictionary that has names...
Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and...
Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and fill it with the names of various sandwiches. Make an empty list called finished_sandwiches. Loop through the list of sandwich orders and spring a message for each order such as "I am working on your tuna sandwich" As each sandwich is made, move it to the list of finished sandwiches. After all the sandwiches have been made, print a message listing each sandwich that...
Let S be the set of all natural numbers that are describable in English words using...
Let S be the set of all natural numbers that are describable in English words using no more than 50 characters (so, 240 is in S since we can describe it as “two hundred forty”, which requires fewer than 50 characters). Assuming that we are allowed to use only the 27 standard characters (the 26 letters of the alphabet and the space character), show that there are only finitely many numbers contained in S. (In fact, perhaps you can show...
Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to...
Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to represent a tic tac toe board, write code to check if the board has a winner.
Python: How would I write a function using list comprehensions to list of integers into two...
Python: How would I write a function using list comprehensions to list of integers into two halves with the evens first, followed by odds? And on top of that, the numbers should be listed in their original order.
(Python) a) Using the the code below write a function that takes the list xs as...
(Python) a) Using the the code below write a function that takes the list xs as input, divides it into nss = ns/nrs chunks (where nrs is an integer input parameter), computes the mean and standard deviation s (square root of the variance) of the numbers in each chunk and saves them in two lists of length nss and return these upon finishing. Hint: list slicing capabilities can be useful in implementing this function. from random import random as rnd...
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT