__zero__

Regex tk

Jan 5th, 2019
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import ttk
  3. from re import match, search
  4.  
  5. root = Tk()
  6. root.title("regex password")
  7. root.resizable(0, 0)
  8. root.geometry("270x250")
  9.  
  10. mode_select = IntVar()
  11. pattern_st = StringVar()
  12. txto = StringVar()
  13. labelout = StringVar()
  14.  
  15. def convert():
  16.     global mode_select, pattern_st, txto, labelout
  17.  
  18.     p = r'%s' % pattern_st.get()
  19.     #searchmode
  20.     if(mode_select.get() == 1):
  21.        
  22.         if(search(p, txto.get())):
  23.             labelout.set("Match")
  24.             print("==== \nPATTERN: %s \nSTRING TO SEARCH: %s\nSEARCH: True" % (p, txto.get() ) )
  25.         else:
  26.             labelout.set("No match")
  27.             print("==== \nPATTERN: %s \nSTRING TO SEARCH: %s\nSEARCH: False" % (p, txto.get() ) )
  28.     #matchmode
  29.     if(mode_select.get() == 2):
  30.         if(match(p, txto.get())):
  31.             labelout.set("Match")
  32.             print("==== \nPATTERN: %s \nSTRING TO MATCH: %s\nMATCH: True" % (p, txto.get() ) )
  33.         else:
  34.             labelout.set("No match")
  35.             print("==== \nPATTERN: %s \nSTRING TO MATCH: %s\nMATCH: False" % (p, txto.get() ) )
  36.  
  37. pattern_label = ttk.Label(root, text="Pattern")
  38. pattern_label.grid(column=0, row=1, padx=20, pady=20)
  39.  
  40. pattern = ttk.Entry(root, textvariable=pattern_st)
  41. pattern.grid(column=1, row=1)
  42.  
  43. #opt:
  44. search_mode = ttk.Radiobutton(root, text="Search mode", variable=mode_select, value=1)
  45. search_mode.grid(column=0, row=2, padx=20, pady=20)
  46.  
  47. match_mode = ttk.Radiobutton(root, text="Match mode", variable=mode_select, value=2)
  48. match_mode.grid(column=1, row=2)
  49.  
  50. txt_to = ttk.Label(root, text="String")
  51. txt_to.grid(column=0, row=3, padx=20, pady=20)
  52. text_to = ttk.Entry(root, textvariable=txto)
  53. text_to.grid(column=1, row=3)
  54.  
  55. go = ttk.Button(root, text="go", command=lambda: convert())
  56. go.grid(column=1, row=4)
  57.  
  58. output = ttk.Label(root, text="Text goes here", textvariable=labelout)
  59. output.grid(column=0, row=6, pady=20)
  60.  
  61. if __name__ == "__main__":
  62.     root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment