repl.it
@AhmadAyyeh/

soundex with Tk

Tkinter

No description

fork
loading
Files
  • main.py
  • nohup.out
main.py
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()