mirror of
https://github.com/serialexperiments0815/OpenLibFetch.git
synced 2026-07-12 15:32:24 +00:00
126 lines
4.2 KiB
Python
126 lines
4.2 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk
|
|
from buttonfade import buttonfade
|
|
#from Requests import search, image
|
|
from request_api import request_api
|
|
import requests
|
|
from io import BytesIO
|
|
from PIL import Image, ImageTk
|
|
|
|
rq = request_api()
|
|
|
|
class BookSelection():
|
|
|
|
def __init__(self):
|
|
self.x = 0
|
|
#self.imageisbn = None
|
|
|
|
def on_searchbutton(self):
|
|
self.x = 0
|
|
searchbar_input = searchbar.get()
|
|
rq.search(searchbar_input)
|
|
self.image_frame()
|
|
self.text_configuration()
|
|
for number in range(len(rq.return_isbn())):
|
|
tk.Label(frame_two, text=f"{rq.return_isbn(number)}").grid(row=number, column=0, pady=10, padx=20, sticky="ew")
|
|
|
|
def text_configuration(self):
|
|
try:
|
|
resulttext.config(text=(
|
|
f"{rq.Booktitle}" + "\n"
|
|
+ f"{rq.Bookauthor}" + "\n"
|
|
+ f"{rq.Bookisbn[self.x]}" + "\n"
|
|
+ f"{rq.Bookdate[self.x]}" + "\n"
|
|
)
|
|
)
|
|
except UnboundLocalError:
|
|
self.x = len(rq.return_isbn())
|
|
imageisbn = (rq.return_isbn(self.x))
|
|
print(imageisbn)
|
|
self.text_configuration()
|
|
self.image_frame(imageisbn)
|
|
|
|
except IndexError:
|
|
self.x = 0
|
|
imageisbn = (rq.return_isbn(self.x))
|
|
self.text_configuration()
|
|
self.image_frame(imageisbn)
|
|
|
|
def image_frame(self, imageisbn=None):
|
|
global photo
|
|
imager = rq.out_image(imageisbn)
|
|
response = requests.get(imager)
|
|
img_data = BytesIO(response.content)
|
|
|
|
photo = Image.open(img_data)
|
|
|
|
img = ImageTk.PhotoImage(photo)
|
|
|
|
imagelabel.config(image=img)
|
|
|
|
imagelabel.image = img
|
|
|
|
def on_leftright_button(self, direction):
|
|
internal_direction = direction
|
|
if internal_direction == "left":
|
|
self.x += 1
|
|
imageisbn = (rq.return_isbn(self.x))
|
|
else:
|
|
self.x -= 1
|
|
imageisbn = (rq.return_isbn(self.x))
|
|
self.image_frame(imageisbn)
|
|
self.text_configuration()
|
|
|
|
if __name__ == "__main__":
|
|
BS = BookSelection()
|
|
|
|
|
|
main = tk.Tk()
|
|
main.geometry("600x600")
|
|
main.minsize(600, 800)
|
|
main.maxsize(600, 800)
|
|
main.title("Book Finder")
|
|
|
|
main.rowconfigure(0, weight=1, minsize=50)
|
|
main.rowconfigure(1, weight=1, minsize=660)
|
|
main.rowconfigure(2, weight=1, minsize=90)
|
|
|
|
main.columnconfigure(0, weight=1, minsize=200)
|
|
main.columnconfigure(1, weight=1, minsize=200)
|
|
main.columnconfigure(2, weight=1, minsize=200)
|
|
|
|
|
|
searchbar = buttonfade(main, placeholder="Search here", justify="center")
|
|
searchbar.grid(row=0, column=0, columnspan=3, sticky="nesw")
|
|
|
|
resulttext = tk.Label(main, text="", wraplength=600)
|
|
resulttext.grid(row=2, column=0, columnspan=2, sticky="nesw")
|
|
|
|
imagelabel = tk.Label(main)
|
|
imagelabel.grid(row=1, column=0, columnspan=2, sticky="nesw")
|
|
|
|
|
|
searchbutton = tk.Button(main, text="Search", command=BS.on_searchbutton)
|
|
searchbutton.grid(row=2, column=2, sticky="nsew", pady=(40,0))
|
|
buttonleft = tk.Button(main, text="forward", command=lambda: BS.on_leftright_button("left"))
|
|
buttonleft.grid(row=2, column=2, sticky="nsew", padx=(100, 0), pady=(0,50))
|
|
buttonright = tk.Button(main, text="back", command=lambda: BS.on_leftright_button("right"))
|
|
buttonright.grid(row=2, column=2, sticky="nswe", padx=(0, 100), pady=(0,50))
|
|
|
|
|
|
|
|
canvas = tk.Canvas(main)
|
|
canvas.grid(row=1, column=2, sticky="nsew")
|
|
|
|
#scrollbar = tk.Scrollbar(main, orient=tk.VERTICAL, command=canvas.yview)
|
|
#scrollbar.grid(row=1, column=2, sticky="nsw")
|
|
#
|
|
#canvas.configure(yscrollcommand=scrollbar.set)
|
|
#canvas.bind('<Configure>', lambda e: canvas.configure(scrollregion = canvas.bbox("all")))
|
|
#
|
|
frame_two = tk.Frame(canvas)
|
|
frame_two.grid(sticky="nsew")
|
|
|
|
canvas.create_window((0, 0), window=frame_two, anchor="nw")
|
|
|
|
main.mainloop()
|