-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshibaboard.py
60 lines (47 loc) · 1.81 KB
/
shibaboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import sys
import json
import requests
import pyperclip
import tkinter as tk
from io import BytesIO
from PIL import Image, ImageTk
url = "http://shibe.online/api/shibes?count=1&urls=true&httpsUrls=true"
class shibaboard(tk.Tk):
def __init__(self):
super().__init__()
self.title("shibaboard")
self.resizable(False, False)
self.ico = ImageTk.PhotoImage(file = "ico.ico")
self.iconphoto(False, self.ico)
# dynamic scaling ? ? ?
x = self.winfo_screenwidth()
y = self.winfo_screenheight()
self.geometry(f"{x // 4}x{y // 2}")
self.update()
# Getting a link to an image
self.r = requests.get(url)
self.json_data = self.r.json()
self.json_data = json.dumps(self.json_data)
self.json_data = self.json_data[2:-2]
# Sending another request to the link we just got
self.r = requests.get(self.json_data)
self.pil_image = Image.open(BytesIO(self.r.content))
self.image = ImageTk.PhotoImage(self.pil_image.resize((self.winfo_width(),self.winfo_height()), Image.ANTIALIAS))
# Put image on label
self.shiba_label = tk.Label(image=self.image)
self.shiba_label.pack()
# Right-click Pop-up menu
self.menu = tk.Menu(self, tearoff = 0)
self.menu.add_command(label = "Copy Link", command = lambda:pyperclip.copy(self.json_data))
self.menu.add_command(label = "Exit", command = lambda:sys.exit(0))
self.shiba_label.bind("<Button-3>", self.evt)
self.shiba_label.bind("<Button-2>", self.evt)
self.mainloop()
# Event handler
def evt(self, event):
try:
self.menu.tk_popup(event.x_root, event.y_root)
finally:
self.menu.grab_release()
while True:
shibaboard()