Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. #event handlers
  4. def btnPrintFrequencyClick(event):#Print letter frequency of input text
  5. pass
  6.  
  7. def btnAutoPrintClick(event):#Print autogenerated text
  8. pass
  9.  
  10. def ChooseEnglish(event):#no comments
  11. btnEnglish["state"] = "disabled"
  12. btnRussian["state"] = "normal"
  13. global AlphabetLength
  14. AlphabetLength = 26
  15.  
  16. def ChooseRussian(event):#no comments
  17. btnRussian["state"] = "disabled"
  18. btnEnglish["state"] = "normal"
  19. global AlphabetLength
  20. AlphabetLength = 33
  21.  
  22. def TxtInputClick(event):#click into the input box
  23. if TxtInput.get("1.0", "1.122") == "Введите текст (все символы, не входящие в алфавит выбранного языка, не будут учитываться в процессе шифровки/расшифровки).":
  24. TxtInput.delete("1.0", END)
  25.  
  26. def TxtOutputClick(event):#click into the output box
  27. if TxtOutput.get("1.0", "1.21") == "Здесь будет результат":
  28. TxtOutput.delete("1.0", END)
  29.  
  30. def IsEnglishLetter(letter):#checked, is letter from English
  31. if(ord(letter)>=65 and ord(letter)<=90) or (ord(letter)>=97 and ord(letter)<=122):#is it english letter
  32. return True
  33. return False
  34.  
  35. def IsRussianLetter(letter):#checked, is letter from Russian
  36. if (ord(letter)==1025 or (ord(letter)>=1040 and ord(letter)<=1103) or ord(letter)==1105):#is it russian letter
  37. return True
  38. return False
  39.  
  40. def EntWithThatClick(event):
  41. pass
  42.  
  43. def EntWhatClick (event):
  44. pass
  45.  
  46. def btnGoClick (event):#changed symbol in the preliminary text
  47. pass
  48.  
  49. def btnCancelClick (event):#deleted preliminary text and output text
  50. pass
  51.  
  52. AlphabetLength = 33
  53.  
  54. #There is user interface######################################################
  55. root = Tk()
  56. root.title( "Шифр перестановками")
  57. root.geometry("1400x515+0+0")
  58.  
  59. TxtInput = Text(root, width = 35, height = 36, bg = "white", fg= "black", wrap = "word")
  60. TxtInput.insert("1.0", "Введите текст (все символы, не входящие в алфавит выбранного языка, не будут учитываться в процессе шифровки/расшифровки).")
  61. TxtInput.bind("<Button-1>", TxtInputClick)
  62. #set focus bind
  63. TxtInput.pack(side = "left")
  64.  
  65. TxtAlphabetFrequency = Text(root, width = 20, height = 36, bg = "white", fg= "black", wrap = "word")
  66. TxtAlphabetFrequency.insert("1.0", "Усреднённая частота использования букв в русском тексте: "
  67. " о - 10.983 \n"
  68. "е - 8.483 \n "
  69. "а - 7.998 \n "
  70. "и - 7.367 \n "
  71. "н - 6.7 \n "
  72. "т - 6.318 \n "
  73. "с - 5.473 \n "
  74. "р - 4.746 \n "
  75. "в - 4.533 \n "
  76. "л - 4.343 \n "
  77. "к - 3.486 \n "
  78. "м - 3.203 \n "
  79. "д - 2.977 \n "
  80. "п - 2.804 \n "
  81. "у - 2.615 \n "
  82. "я - 2.001 \n "
  83. "ы - 1.898 \n "
  84. "ь - 1.735 \n "
  85. "г - 1.687 \n "
  86. "з - 1.641 \n "
  87. "б - 1.592 \n "
  88. "ч - 1.45 \n "
  89. "й - 1.208 \n "
  90. "х - 0.966 \n "
  91. "ж - 0.94 \n "
  92. "ш - 0.718 \n "
  93. "ю - 0.638 \n "
  94. "ц - 0.486 \n "
  95. "щ - 0.361 \n "
  96. "э - 0.331 \n "
  97. "ф - 0.267 \n "
  98. "ъ - 0.037 \n "
  99. "ё - 0.013 \n ")
  100. #set focus bind
  101. TxtAlphabetFrequency.pack(side = "left")
  102.  
  103. TxtInputTextFrequency = Text(root, width = 20, height = 36, bg = "white", fg= "black", wrap = "word")
  104. TxtInputTextFrequency.insert("1.0", "Частота вводимого текста: \n\n")
  105. #set focus bind
  106. TxtInputTextFrequency.pack(side = "left")
  107.  
  108. frame1=Frame(root)
  109. frame1.pack(side='left', padx=10)
  110.  
  111. frame2=Frame(frame1)
  112. frame2.pack(side='top', padx=10)
  113. btnRussian = Button(frame2, text="Русский язык", width=13, height=3, bg= "Silver", fg= "black")
  114. btnRussian.bind("<Button-1>", ChooseRussian)
  115. btnRussian.pack(side ='left', pady=4)
  116. btnRussian["state"] = "disabled"
  117.  
  118. btnEnglish = Button(frame2, text="Английский язык", width=13, height=3, bg= "Silver", fg= "black")
  119. btnEnglish.bind("<Button-1>", ChooseEnglish)
  120. btnEnglish.pack(side ='right', pady=3)
  121.  
  122. frame3=Frame(frame1)
  123. frame3.pack(side='top', padx=10)
  124.  
  125. EntWhat = Entry(frame3, width=4, bg = "white", fg = "black", justify="center")
  126. EntWhat.insert(INSERT, "что")
  127. EntWhat.bind("<Button-1>", EntWhatClick)
  128. EntWhat.config(font =("Times", 16))
  129. EntWhat.pack(side = "left", pady= 10)
  130.  
  131. btnGo = Button(frame3, text="-->", width=5, height = 1, bg= "Silver", fg= "black")
  132. btnGo.bind("<Button-1>", btnGoClick)
  133. btnGo.pack(side='left', padx=10)
  134.  
  135. EntWithThat = Entry(frame3, width=4, bg = "white", fg = "black", justify="center")
  136. EntWithThat.insert(INSERT, "чем")
  137. EntWithThat.bind("<Button-1>", EntWithThatClick)
  138. EntWithThat.config(font =("Times", 16))
  139. EntWithThat.pack(side = "left", pady= 10)
  140.  
  141. frame4 = Frame(frame1)
  142. frame4.pack(side='top', padx=10)
  143.  
  144. btnPrint = Button(frame1, text="Рассчитать частоту", width=30, height = 5, bg= "Silver", fg= "black")
  145. btnPrint.bind("<Button-1>", btnPrintFrequencyClick)
  146. btnPrint.pack(side='top', padx=10)
  147.  
  148. btnAutoPrint = Button(frame1, text="Вывести автовариант", width=30, height = 5, bg= "Silver", fg= "black")
  149. btnAutoPrint.bind("<Button-1>", btnAutoPrintClick)
  150. btnAutoPrint.pack(side='top', pady=10)
  151.  
  152. btnCancel = Button(frame1, text="Отменить", width=30, height = 5, bg= "Silver", fg= "black")
  153. btnCancel.bind("<Button-1>", btnCancelClick)
  154. btnCancel.pack(side='top', pady=10)
  155.  
  156. TxtOutput = Text(root, width = 35, height = 36, bg = "white", fg= "black", wrap = "word")
  157. TxtOutput.insert(INSERT, "Здесь будет результат")
  158. TxtOutput.bind("<Button-1>", TxtOutputClick)
  159. TxtOutput.pack(side = 'right')
  160.  
  161. TxtOutput = Text(root, width = 35, height = 36, bg = "white", fg= "black", wrap = "word")
  162. TxtOutput.insert(INSERT, "Здесь будет автовариант")
  163. TxtOutput.bind("<Button-1>", TxtOutputClick)
  164. TxtOutput.pack(side = 'right')
  165. ########################################################
  166.  
  167. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement