Monday, 6 November 2023

Write Python GUI program which accepts a number n to displays each digit of number in words.

 

Write Python GUI program which accepts a number n to displays each digit of number in words.    

 

import tkinter as tk

 

def digit_to_word(digit):

    words = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]

    return words[digit]

 

def display_digits_in_words():

    number = entry.get()

    word_representation = " ".join([digit_to_word(int(digit)) for digit in number])

    result_label.config(text=word_representation)

 

# Create the main window

root = tk.Tk()

root.title("Number to Words")

 

# Entry widget for entering the number

entry = tk.Entry(root)

entry.pack()

 

# Button to convert and display the digits in words

convert_button = tk.Button(root, text="Convert", command=display_digits_in_words)

convert_button.pack()

 

# Label to display the word representation

result_label = tk.Label(root, text="", font=("Arial", 12))

result_label.pack()

 

root.mainloop()