Question

Please Help me to create Morse code program on python3 by using tkinter ?

Please
Help me to create Morse code program on python3 by using tkinter ?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Points to consider:

  1. We need to make a GUI and input in it to find the result
  2. The result will be displayed in the output field.
  3. You can input the lowercase characters in the input field.

Code

import tkinter as tk
class Morse:
    def __init__(self):
        self.m = tk.Tk()

        self.out = tk.StringVar()
        label1 = tk.Label(self.m, text = 'Input')
        self.input = tk.Entry(self.m)
        label2 = tk.Label(self.m, text = 'Output')
        self.output = tk.Entry(self.m, textvariable=self.out)
        self.button = tk.Button(self.m, text = 'Find', command=self.morseCode)

        label1.pack(side='left')
        self.input.pack(side='left')
        label2.pack(side='left')
        self.output.pack(side='left')
        self.button.pack(side='left')
        tk.mainloop()

    def morseEncode(self,x):
        # refer to the Morse table
        # image attached in the article
        if x == 'a':
            return ".-"
        elif x == 'b':
            return "-..."
        elif x == 'c':
            return "-.-."
        elif x == 'd':
            return "-.."
        elif x == 'e':
            return "."
        elif x == 'f':
            return "..-."
        elif x == 'g':
            return "--."
        elif x == 'h':
            return "...."
        elif x == 'i':
            return ".."
        elif x == 'j':
            return ".---"
        elif x == 'k':
            return "-.-"
        elif x == 'l':
            return ".-.."
        elif x == 'm':
            return "--"
        elif x == 'n':
            return "-."
        elif x == 'o':
            return "---"
        elif x == 'p':
            return ".--."
        elif x == 'q':
            return "--.-"
        elif x == 'r':
            return ".-."
        elif x == 's':
            return "..."
        elif x == 't':
            return "-"
        elif x == 'u':
            return "..-"
        elif x == 'v':
            return "...-"
        elif x == 'w':
            return ".--"
        elif x == 'x':
            return "-..-"
        elif x == 'y':
            return "-.--"
        elif x == 'z':
            return "--.."

    def morseCode(self  ):
        s = self.input.get()
        output = ''
        for character in s:
            output += self.morseEncode(character)
        self.out.set(output)



if __name__ == "__main__":
    Morse()

Code Snippet

Output Snippet

Friend, That was a nice question to answer
If you have any doubts in understanding do let me know in the comment section. I will be happy to help you further.
Please like it if you think effort deserves like.
Thanks

Add a comment
Know the answer?
Add Answer to:
Please Help me to create Morse code program on python3 by using tkinter ?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT