📜  使用Python创建一个使用 IFSC 代码搜索银行信息的 GUI

📅  最后修改于: 2022-05-13 01:54:20.799000             🧑  作者: Mango

使用Python创建一个使用 IFSC 代码搜索银行信息的 GUI

先决条件: Python GUI – tkinter

以下程序描述了如何使用Python脚本来制定 GUI 应用程序,以使用 IFSC 代码获取银行详细信息。在这里,我们使用Razorpay IFSC Toolkit来获取 IFSC 代码。 Razorpay IFSC 工具包通过其工具包处理 IFSC 代码并返回数据集。

所需模块:请求

Requests允许您非常轻松地发送 HTTP/1.1 请求。这不是Python内置的,因此必须明确安装。

要安装此模块,只需在终端中键入以下命令:

pip install requests

方法:

  • 导入模块
  • 将 Url 和 IFSC 代码传递给 requests.get()函数
  • 获取此 JSON 响应
  • 它以 Dict 数据类型返回银行详细信息

程序:

Python3
import requests
  
IFSC_Code ='KKBK0005652'
URL = "https://ifsc.razorpay.com/"
result = requests.get(URL+IFSC_Code).json()
print(result)


Python3
# import modules
from tkinter import *
from tkinter import messagebox
import requests
  
  
def getifsc():
    try:
        IFSC_Code = e.get()
        URL = "https://ifsc.razorpay.com/"
        result = requests.get(URL+IFSC_Code).json()
        Centre.set(result['CENTRE'])
        contact.set(result['CONTACT'])
        UPI.set(result['UPI'])
        CITY.set(result['CITY'])
        STATE.set(result['STATE'])
        DISTRICT.set(result['DISTRICT'])
        IMPS.set(result['IMPS'])
        ADDRESS.set(result['ADDRESS'])
        BRANCH.set(result['BRANCH'])
        STD.set(result['STD CODE'])
        MICR.set(result['MICR CODE'])
        BANK.set(result['BANK'])
        BANKCODE.set(result['BANKCODE'])
        IFSC.set(result['IFSC'])
    except:
        messagebox.showerror("showerror", "Something wrong")
  
  
# object of tkinter
# and background set for light grey
master = Tk()
master.configure(bg='light grey')
  
# Variable Classes in tkinter
Centre = StringVar()
contact = StringVar()
UPI = StringVar()
CITY = StringVar()
STATE = StringVar()
DISTRICT = StringVar()
IMPS = StringVar()
ADDRESS = StringVar()
BRANCH = StringVar()
STD = StringVar()
MICR = StringVar()
BANK = StringVar()
BANKCODE = StringVar()
IFSC = StringVar()
  
  
# Creating label for each information
# name using widget Label
Label(master, text="Enter IFSC Code :", bg="light grey").grid(row=0, sticky=W)
Label(master, text="Bank Name :", bg="light grey").grid(row=1, sticky=W)
Label(master, text="Centre :", bg="light grey").grid(row=2, sticky=W)
Label(master, text="contact :", bg="light grey").grid(row=3, sticky=W)
Label(master, text="UPI :", bg="light grey").grid(row=4, sticky=W)
Label(master, text="CITY :", bg="light grey").grid(row=5, sticky=W)
Label(master, text="STATE :", bg="light grey").grid(row=6, sticky=W)
Label(master, text="DISTRICT :", bg="light grey").grid(row=7, sticky=W)
Label(master, text="ADDRESS :", bg="light grey").grid(row=8, sticky=W)
Label(master, text="BRANCH :", bg="light grey").grid(row=9, sticky=W)
Label(master, text="STD :", bg="light grey").grid(row=10, sticky=W)
Label(master, text="MICR :", bg="light grey").grid(row=11, sticky=W)
Label(master, text="IFSC :", bg="light grey").grid(row=12, sticky=W)
  
  
# Creating lebel for class variable
# name using widget Entry
Label(master, text="", textvariable=BANK,
      bg="light grey").grid(row=1, column=1, sticky=W)
Label(master, text="", textvariable=Centre,
      bg="light grey").grid(row=2, column=1, sticky=W)
Label(master, text="", textvariable=contact,
      bg="light grey").grid(row=3, column=1, sticky=W)
Label(master, text="", textvariable=UPI, bg="light grey").grid(
    row=4, column=1, sticky=W)
Label(master, text="", textvariable=CITY,
      bg="light grey").grid(row=5, column=1, sticky=W)
Label(master, text="", textvariable=STATE,
      bg="light grey").grid(row=6, column=1, sticky=W)
Label(master, text="", textvariable=DISTRICT,
      bg="light grey").grid(row=7, column=1, sticky=W)
Label(master, text="", textvariable=ADDRESS,
      bg="light grey").grid(row=8, column=1, sticky=W)
Label(master, text="", textvariable=BRANCH,
      bg="light grey").grid(row=9, column=1, sticky=W)
Label(master, text="", textvariable=STD, bg="light grey").grid(
    row=10, column=1, sticky=W)
Label(master, text="", textvariable=MICR, bg="light grey").grid(
    row=11, column=1, sticky=W)
Label(master, text="", textvariable=IFSC, bg="light grey").grid(
    row=12, column=1, sticky=W)
  
  
e = Entry(master)
e.grid(row=0, column=1)
  
# creating a button using the widget
# Button that will call the submit function
b = Button(master, text="Show", command=getifsc)
b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5)
  
mainloop()


输出:

程序2:(使用IFSC代码搜索银行详细信息的GUI应用程序概念类似于上述实现)

蟒蛇3

# import modules
from tkinter import *
from tkinter import messagebox
import requests
  
  
def getifsc():
    try:
        IFSC_Code = e.get()
        URL = "https://ifsc.razorpay.com/"
        result = requests.get(URL+IFSC_Code).json()
        Centre.set(result['CENTRE'])
        contact.set(result['CONTACT'])
        UPI.set(result['UPI'])
        CITY.set(result['CITY'])
        STATE.set(result['STATE'])
        DISTRICT.set(result['DISTRICT'])
        IMPS.set(result['IMPS'])
        ADDRESS.set(result['ADDRESS'])
        BRANCH.set(result['BRANCH'])
        STD.set(result['STD CODE'])
        MICR.set(result['MICR CODE'])
        BANK.set(result['BANK'])
        BANKCODE.set(result['BANKCODE'])
        IFSC.set(result['IFSC'])
    except:
        messagebox.showerror("showerror", "Something wrong")
  
  
# object of tkinter
# and background set for light grey
master = Tk()
master.configure(bg='light grey')
  
# Variable Classes in tkinter
Centre = StringVar()
contact = StringVar()
UPI = StringVar()
CITY = StringVar()
STATE = StringVar()
DISTRICT = StringVar()
IMPS = StringVar()
ADDRESS = StringVar()
BRANCH = StringVar()
STD = StringVar()
MICR = StringVar()
BANK = StringVar()
BANKCODE = StringVar()
IFSC = StringVar()
  
  
# Creating label for each information
# name using widget Label
Label(master, text="Enter IFSC Code :", bg="light grey").grid(row=0, sticky=W)
Label(master, text="Bank Name :", bg="light grey").grid(row=1, sticky=W)
Label(master, text="Centre :", bg="light grey").grid(row=2, sticky=W)
Label(master, text="contact :", bg="light grey").grid(row=3, sticky=W)
Label(master, text="UPI :", bg="light grey").grid(row=4, sticky=W)
Label(master, text="CITY :", bg="light grey").grid(row=5, sticky=W)
Label(master, text="STATE :", bg="light grey").grid(row=6, sticky=W)
Label(master, text="DISTRICT :", bg="light grey").grid(row=7, sticky=W)
Label(master, text="ADDRESS :", bg="light grey").grid(row=8, sticky=W)
Label(master, text="BRANCH :", bg="light grey").grid(row=9, sticky=W)
Label(master, text="STD :", bg="light grey").grid(row=10, sticky=W)
Label(master, text="MICR :", bg="light grey").grid(row=11, sticky=W)
Label(master, text="IFSC :", bg="light grey").grid(row=12, sticky=W)
  
  
# Creating lebel for class variable
# name using widget Entry
Label(master, text="", textvariable=BANK,
      bg="light grey").grid(row=1, column=1, sticky=W)
Label(master, text="", textvariable=Centre,
      bg="light grey").grid(row=2, column=1, sticky=W)
Label(master, text="", textvariable=contact,
      bg="light grey").grid(row=3, column=1, sticky=W)
Label(master, text="", textvariable=UPI, bg="light grey").grid(
    row=4, column=1, sticky=W)
Label(master, text="", textvariable=CITY,
      bg="light grey").grid(row=5, column=1, sticky=W)
Label(master, text="", textvariable=STATE,
      bg="light grey").grid(row=6, column=1, sticky=W)
Label(master, text="", textvariable=DISTRICT,
      bg="light grey").grid(row=7, column=1, sticky=W)
Label(master, text="", textvariable=ADDRESS,
      bg="light grey").grid(row=8, column=1, sticky=W)
Label(master, text="", textvariable=BRANCH,
      bg="light grey").grid(row=9, column=1, sticky=W)
Label(master, text="", textvariable=STD, bg="light grey").grid(
    row=10, column=1, sticky=W)
Label(master, text="", textvariable=MICR, bg="light grey").grid(
    row=11, column=1, sticky=W)
Label(master, text="", textvariable=IFSC, bg="light grey").grid(
    row=12, column=1, sticky=W)
  
  
e = Entry(master)
e.grid(row=0, column=1)
  
# creating a button using the widget
# Button that will call the submit function
b = Button(master, text="Show", command=getifsc)
b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5)
  
mainloop()

输出: