Facebook
From Funky Hog, 5 Years ago, written in Python.
This paste is a reply to Untitled from Bitty Monkey - go back
Embed
Viewing differences between Untitled and Re: Untitled
from tkinter import *
import winsound as ws

alfabet = {
'A' : '.-',     'N' : '-.',     'B' :'-...',    'O' : '---',    'C' :'-.-.',    'P' : '.--.',   'D' :'-..',     'Q' : '--.-',   'E' :'.',       'R' : '.-.',
'F' :'..-.',    'S' : '...',    'G' :'--.',     'T' : '-',      'H' :'....',    'U' : '..-',    'I' :'..',      'V' : '...-',   'J' :'.---',    'W' : '.--',
'K' :'-.-',     'X' : '-..-',   'L' :'.-..',    'Y' : '-.--',   'M' :'--',      'Z' : '--..' }


class Morse:

    def __init__(self, okno):
        self.okno = okno
        self.var = StringVar()
        self.var2 = StringVar()
        okno.title("Konwenter sygnałów Morse'a")
        self.etykieta1 = Label(okno, text="Wprowadź w poniższe pole tekst do przetłumaczenia na alfabet Morse'a")
        self.tekst1 = Entry(okno, textvariable = self.var, width = 70)
        self.przycisk1 = Button(okno, text="Przetłumacz tekst na alfabet Morse'a", command = self.nasygnal)

        self.etykieta2 = Label(okno, text="Wprowadź w poniższe pole kod Morse'a do przetłumaczenia na tekst")
        self.tekst2 = Entry(okno, textvariable=self.var2, width=70)
        self.przycisk2 = Button(okno, text="Przetłumacz kod Morse'a na tekst", command = self.natekst)

        self.etykieta1.pack(pady=(5, 0))
        self.tekst1.pack(pady=(5, 0))
        self.przycisk1.pack(pady=(10, 0))
        self.etykieta2.pack(pady=(40, 0))
        self.tekst2.pack(pady=(5, 0))
        self.przycisk2.pack(pady=(10, 0))

    def nasygnal(self):
        text = self.var.get()
        self.sygnal = ''
        for znak in text:
            self.sygnal += alfabet[znak.upper()]
        print (self.sygnal)
        print ( len(self.sygnal))
        for char in self.sygnal:
            if char == '.':
                ws.Beep(1000, 300)
            else:
                ws.Beep(1000, 800)

    def natekst(self):
        morse_inv = {}
        for k, v in alfabet.items():
            morse_inv[v] = k
        print(morse_inv)
        kod = self.var2.get()
        self.tekst = ''
        aa = kod.rsplit('/')
        for word in aa:
            b = str(morse_inv[word])
            self.tekst += b
            print(word)
        print(self.tekst)


okno = Tk()
Wpisy = Morse(okno)
okno.geometry('700x300')
okno.mainloop()
captcha