Имеется код на языке python, необходимо обернуть его в графический интерфейс
import pymysql
from config import host, user, passw, db_name
try:
connection = pymysql.connect(
host=host,
port=3306,
user=user,
password=passw,
database=db_name,
cursorclass=pymysql.cursors.DictCursor
)
print("успех")
def new_oper():
input_sum = input("Введите сумму: ")
if action == "внесение":
with connection.cursor() as cursor:
operation = 'INSERT INTO oper (num_card, type, money, oper_date) VALUES (' + str(
input_number_card) + ', "+", ' + str(input_sum) + ',CURRENT_TIME);'
cursor.execute(operation)
connection.commit()
elif action == "снятие":
with connection.cursor() as cursor:
info = 'SELECT num_card,balance FROM `cards` WHERE num_card = 6381592740563821'
cursor.execute(info)
rows = cursor.fetchall()
balance = rows[0]["balance"]
if float(balance) < float(input_sum):
print("Не хватает средств на счету")
else:
operation = 'INSERT INTO oper (num_card, type, money, oper_date) VALUES (' + str(
input_number_card) + ', "-", ' + str(input_sum) + ',CURRENT_TIME);'
cursor.execute(operation)
connection.commit()
interfeic()
#фунция по получению информации по карте
def zapros_info():
with connection.cursor() as cursor:
info = 'SELECT num_card,balance FROM `cards` WHERE num_card = 6381592740563821'
cursor.execute(info)
rows = cursor.fetchall()
print(type(rows))
num_card = print(rows[0]["num_card"])
balance = print(rows[0]["balance"])
last_opers = 'SELECT type, money, oper_date FROM `oper` WHERE num_card = 6381592740563821 LIMIT 5;'
cursor.execute(info)
cursor.execute(last_opers)
rows = cursor.fetchall()
for row in rows:
if row["type"] == "+":
print("Внесение ", row['money'], row['oper_date'])
else:
print("Снятие ", row['money'], row['oper_date'])
interfeic()
#функция снятия/внесения
def login():
global input_number_card
input_number_card = input("CARD:")
with connection.cursor() as cursor:
log_info = 'SELECT pin FROM `cards` WHERE num_card = '+str(input_number_card)
cursor.execute(log_info)
rows = cursor.fetchall()
block = blocked_card()
true_pin = rows[0]["pin"]
print(true_pin)
if str(input("PIN:")) == str(true_pin) and block != True:
interfeic()
elif block == True:
print("Карта заблокирована")
login()
else:
i = 1
print("Неправильный PIN\n" + "Количество попыток: " + str(3-i))
while input("PIN:") != true_pin:
i +=1
print("Неправильный PIN\n" + "Количество попыток: " + str(3-i))
if i == 3:
with connection.cursor() as cursor:
for_block = 'UPDATE cards SET status = "freeze" WHERE num_card = ' + str(input_number_card)
cursor.execute(for_block)
connection.commit()
print("Карта заблокирована")
login()
def blocked_card():
with connection.cursor() as cursor:
info = 'SELECT status FROM cards WHERE num_card = ' + str(input_number_card)
cursor.execute(info)
rows = cursor.fetchall()
stat = rows[0]["status"]
if stat == 'freeze' or stat == 'block':
return True
else:
return False
def interfeic():
print("Ваше действие:")
global action
action = input()
if action == "информация по карте":
zapros_info()
elif action == "внесение":
new_oper()
elif action == "снятие":
new_oper()
elif action == "вернуть карту":
login()
login()
except Exception as ex:
print("Connection...")
print(ex)
Имеется графический интерфейс, но не понимаю, как это соединить, поскольку интерфейс писал одногруппник:
import tkinter as tk
class ATMInterface:
def __init__(self, root):
self.root = root
self.root.geometry("400x300")
self.input_num_card = None
self.input_pin = None
self.num_card = "1234567890123456"
self.balance = 1000
self.last_opers = ["Operation 1", "Operation 2", "Operation 3"]
self.login()
def destroy_widgets(self):
for widget in self.root.winfo_children():
widget.destroy()
def login(self):
self.destroy_widgets()
label = tk.Label(self.root, text="Введите номер карты:")
label.pack()
self.input_num_card = tk.Entry(self.root)
self.input_num_card.pack()
button = tk.Button(self.root, text="Далее", command=self.enter_pin)
button.pack()
def enter_pin(self):
self.destroy_widgets()
label = tk.Label(self.root, text="Введите пин-код:")
label.pack()
self.input_pin = tk.Entry(self.root, show="*")
self.input_pin.pack()
button = tk.Button(self.root, text="Вход", command=self.interfeic)
button.pack()
def interfeic(self):
self.destroy_widgets()
label = tk.Label(self.root, text="Главный экран")
label.pack()
button1 = tk.Button(self.root, text="Информация по карте", command=self.zapros_info)
button1.pack()
button2 = tk.Button(self.root, text="Снятие наличных", command=self.cash_withdrawal)
button2.pack()
button3 = tk.Button(self.root, text="Внесение наличных", command=self.cash_deposit)
button3.pack()
button4 = tk.Button(self.root, text="Вернуть карту", command=self.login)
button4.pack()
def zapros_info(self):
self.destroy_widgets()
label1 = tk.Label(self.root, text="Номер карты: {}".format(self.num_card))
label1.pack()
label2 = tk.Label(self.root, text="Баланс: {}".format(self.balance))
label2.pack()
label3 = tk.Label(self.root, text="Последние операции:")
label3.pack()
for oper in self.last_opers:
label_oper = tk.Label(self.root, text=oper)
label_oper.pack()
button = tk.Button(self.root, text="Назад", command=self.interfeic)
button.pack()
def cash_withdrawal(self):
self.destroy_widgets()
label = tk.Label(self.root, text="Введите сумму для снятия:")
label.pack()
entry = tk.Entry(self.root)
entry.pack()
button = tk.Button(self.root, text="Главный экран", command=self.interfeic)
button.pack()
def cash_deposit(self):
self.destroy_widgets()
label = tk.Label(self.root, text="Введите сумму для внесения:")
label.pack()
entry = tk.Entry(self.root)
entry.pack()
button = tk.Button(self.root, text="Главный экран", command=self.interfeic)
button.pack()
root = tk.Tk()
app = ATMInterface(root)
root.mainloop()