Files
2026-10-19 20:29:13 +02:00

108 lines
3.0 KiB
Python

import tkinter as tk
from my_package.App_window import AppWindow
def is_valid_isbn(entry):
clean_isbn = entry.replace("-", "").replace(" ", "").upper()
if len(clean_isbn) != 10:
return False
total = 0
try:
for i in range(10):
char = clean_isbn[i]
if i == 9 and char == 'X':
value = 10
elif char.isdigit():
value = int(char)
else:
return False
total += value * (10 - i)
return total % 11 == 0
except Exception:
return False
def is_valid_iban(entry):
clean_iban = entry.replace(" ", "").upper()
rearranged = clean_iban[4:] + clean_iban[:4]
numeric_iban = ""
for char in rearranged:
if char.isdigit():
numeric_iban += char
else:
numeric_iban += str(ord(char) - 55)
return int(numeric_iban) % 97 == 1
class Checker(AppWindow):
def __init__(self):
super().__init__(300,300)
self.button_1 = tk.Button(self.root, text="check", command= self.check_isbn)
self.button_2 = tk.Button(self.root,text="check", command= self.check_iban)
self.isbn_label = tk.Label(self.root, text="")
self.iban_label = tk.Label(self.root, text="")
self.entry_1 = tk.Entry(self.root, width=20)
self.entry_2 = tk.Entry(self.root, width=20)
def init_widgets(self):
tk.Label(self.root, text="ISBN: ").grid(row=0, column=0)
self.entry_1.grid(row=0, column=1)
self.button_1.grid(row=1, column=0)
self.isbn_label.grid(row=1, column=1)
tk.Label(self.root, text="IBAN: ").grid(row=2, column=0)
self.entry_2.grid(row=2, column=1)
self.button_2.grid(row=3, column=0)
self.iban_label.grid(row=3, column=1)
def check_isbn(self):
entry = self.entry_1.get()
self.entry_1.delete(0, tk.END)
if is_valid_isbn(entry):
self.isbn_label.configure(text="Valid ISBN")
else:
self.isbn_label.configure(text="Invalid ISBN")
def check_iban(self):
entry = self.entry_2.get()
self.entry_2.delete(0, tk.END)
if is_valid_iban(entry):
self.iban_label.configure(text="Valid IBAN")
else:
self.iban_label.configure(text="Invalid IBAN")
def console_checker():
print("Welcome to IBAN / ISBN Checker")
while True:
usr_input = input("Please enter your Number: ")
print("1. Check ISBN")
print("2. Check IBAN")
print("3. Exit")
usr_choice = input("1 / 2 / 3 ?: ")
if usr_choice == "1":
if is_valid_isbn(usr_input):
print("Valid ISBN")
else:
print("Invalid ISBN")
if usr_choice == "2":
if is_valid_iban(usr_input):
print("Valid IBAN")
else:
print("Invalid IBAN")
if usr_choice == "3":
break
def main():
app = Checker()
app.run()
console_checker()