@AhmadAyyeh/

soundex with Tk

Tkinter

No description

fork
loading
Files
  • main.py
  • nohup.out

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.7162931609151293","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"ZnJvbSB0a2ludGVyIGltcG9ydCAqCmZyb20gdGtpbnRlciBpbXBvcnQgdHRrCgpyb290ID0gVGsoKQpyb290LnRpdGxlKCdSYW5kb20nKQojTGFiZWwodGV4dD0nSG93IG1hbnkgc3F1YXJlcz8gKGV4OiA0eDQsIDV4MyknKS5wYWNrKHNpZGU9VE9QLHBhZHg9MTAscGFkeT0xMCkKCiNlbnRyeSA9IEVudHJ5KHJvb3QsIHdpZHRoPTEwKQojZW50cnkucGFjayhzaWRlPVRPUCxwYWR4PTEwLHBhZHk9MTApCgpkZWYgb25vaygpOgogICAgeCwgeSA9IGVudHJ5LmdldCgpLnNwbGl0KCd4JykKICAgIGZvciByb3cgaW4gcmFuZ2UoaW50KHkpKToKICAgICAgICBmb3IgY29sIGluIHJhbmdlKGludCh4KSk6CiAgICAgICAgICAgIHByaW50KChjb2wsIHJvdykpCgojQnV0dG9uKHJvb3QsIHRleHQ9J09LJywgY29tbWFuZD1vbm9rKS5wYWNrKHNpZGU9TEVGVCkKI0J1dHRvbihyb290LCB0ZXh0PSdDTE9TRScpLnBhY2soc2lkZT0gUklHSFQpCgpkZWYgc291bmRleCgpOgogIGRlZiBnZXRfZGF0YShldmVudD1Ob25lKToKICAgIGZvciBpIGluIHNvdW5kZXhfY29kZToKICAgICAgcHJpbnQgKGkgLCBlbmQgPSAnJyApCiAgZGVmIGJpbmRfYnV0dG9uKGV2ZW50PU5vbmUpOgogICAgaWYgYm9vbFZhci5nZXQoKToKICAgICAgQnV0dG9uLnVuYmluZCgiPEJ1dHRvbi0xPiIpCiAgICBlbHNlOgogICAgICBCdXR0b24uYmluZCgiPEJ1dHRvbi0xPiIgLCBnZXRfZGF0YSkKICBzb3VuZGV4X2NvZG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sgMV0gaW4gRklWRVM6CiAgICAgICAgZGVsIGxhc3RfbmFtZVt4ICsgMV0KICAgICAgc291bmRleF9jb2RlLmFwcGVuZCg1KQogICAgZWxpZiBsYXN0X25hbWVbeF0gPT0gJ1InOgogICAgICBpZiBsYXN0X25hbWVbeCArIDFdID09ICdSJzoKICAgICAgICBkZWwgbGFzdF9uYW1lW3ggKyAxXQogICAgICBzb3VuZGV4X2NvZGUuYXBwZW5kKDYpCiAgaWYgbGVuKHNvdW5kZXhfY29kZSkgPT0gMToKICAgIHNvdW5kZXhfY29kZS5hcHBlbmQoMCkgLCBzb3VuZGV4X2NvZGUuYXBwZW5kKDApICwgc291bmRleF9jb2RlLmFwcGVuZCgwKQogIGVsaWYgbGVuKHNvdW5kZXhfY29kZSkgPT0gMjoKICAgIHNvdW5kZXhfY29kZS5hcHBlbmQgKDApICwgc291bmRleF9jb2RlLmFwcGVuZCgwKQogIGVsaWYgbGVuKHNvdW5kZXhfY29kZSkgPT0zOgogICAgc291bmRleF9jb2RlLmFwcGVuZCgwKSAgCiAgQnV0dG9uKHJvb3QsIHRleHQ9J09LJywgY29tbWFuZD1nZXRfZGF0YSkucGFjayhzaWRlID0gTEVGVCkKICBCdXR0b24ocm9vdCwgdGV4dD0nQ0xPU0UnKS5wYWNrKHNpZGU9IFJJR0hUKQogICNCdXR0b24uYmluZCgiPEJ1dHRvbi0xPiIgLCBnZXRfZGF0YSkKICAjbGFzdF9uYW1lRW50cnkgPSBFbnRyeShyb290LCB0ZXh0dmFyaWFibGUgPSBsYXN0X25hbWUpCiAgI2xhc3RfbmFtZUVudHJ5LnBhY2soc2lkZSA9TEVGVCkKc291bmRleCgpCnJvb3QubWFpbmxvb3AoKQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from tkinter import *
from tkinter import ttk

root = Tk()
root.title('Random')
#Label(text='How many squares? (ex: 4x4, 5x3)').pack(side=TOP,padx=10,pady=10)

#entry = Entry(root, width=10)
#entry.pack(side=TOP,padx=10,pady=10)

def onok():
    x, y = entry.get().split('x')
    for row in range(int(y)):
        for col in range(int(x)):
            print((col, row))

#Button(root, text='OK', command=onok).pack(side=LEFT)
#Button(root, text='CLOSE').pack(side= RIGHT)

def soundex():
  def get_data(event=None):
    for i in soundex_code:
      print (i , end = '' )
  def bind_button(event=None):
    if boolVar.get():
      Button.unbind("<Button-1>")
    else:
      Button.bind("<Button-1>" , get_data)
  soundex_code = []
  last_name = StringVar()
  boolVar = BooleanVar()
  boolVar.set(True)
  check_button = Checkbutton(root, text = "Switch" , variable = boolVar)
  
  check_button.bind("<Button-1>" , bind_button)
  check_button.pack(side = LEFT)
  Label(text='What is your last name? ').pack(side=TOP,padx=10,pady=10)
  entry = Entry(root, width=10)
  entry.pack(side=TOP,padx=10,pady=10)
  soundex_code.append(str(entry)[0])
  #this block of code will delete a doubled letter if there's double letters in the last name.
  ONES = ("B" , "P" , "F" , "V")
  TWOS = ("C" , "S" , "K" , "G" , "J" , "Q" , "X" , "Z")
  THREES = ('D' , 'T')
  FIVES = ('M' , 'N')
  IGNORED = ('A' , 'E' , 'I' , 'O' , 'U' , 'W' , 'Y' , 'H')
  last_name = list(str(entry))
  if " " in last_name:
    last_name.remove(" ")
  for i in range (0, len(last_name) - 1):
    j = i + 1
    if last_name[j] == last_name[i]:
        del last_name[j]
        last_name.append(i)
    if last_name[i] in IGNORED:
      last_name.remove(last_name[i])
      last_name.append(i)
  #converting surname characters into a code.
  for x in range (1 , 4):
    if last_name[x] in ONES:
      if last_name [x+1] in ONES:
        del last_name[x + 1]
      soundex_code.append(1)
    elif last_name[x] in TWOS:
      if last_name[x + 1] in TWOS:
        del last_name [x + 1]
      soundex_code.append(2)
    elif last_name[x] in THREES:
      if last_name[x + 1] in THREES:
        del last_name[x + 1]
      soundex_code.append(3)
    elif last_name[x] == 'L':
      if last_name[x + 1] == 'L':
        del last_name[x + 1]
      soundex_code.append(4)
    elif last_name[x] in FIVES:
      if last_name[x + 1] in FIVES:
        del last_name[x + 1]
      soundex_code.append(5)
    elif last_name[x] == 'R':
      if last_name[x + 1] == 'R':
        del last_name[x + 1]
      soundex_code.append(6)
  if len(soundex_code) == 1:
    soundex_code.append(0) , soundex_code.append(0) , soundex_code.append(0)
  elif len(soundex_code) == 2:
    soundex_code.append (0) , soundex_code.append(0)
  elif len(soundex_code) ==3:
    soundex_code.append(0)  
  Button(root, text='OK', command=get_data).pack(side = LEFT)
  Button(root, text='CLOSE').pack(side= RIGHT)
  #Button.bind("<Button-1>" , get_data)
  #last_nameEntry = Entry(root, textvariable = last_name)
  #last_nameEntry.pack(side =LEFT)
soundex()
root.mainloop()