猫史档案馆


【Python作品分享】作品信息【作品秀】

用户:StarWorldStudio🅥StarWorldStudio🅥查看:0 回复:0 评论:0 创建时间:2021-03-06T07:08:51


【作品展示】

center_image

 

【作品介绍】

使用编程猫API获取作品信息

 

【作品源代码】

import urllib.request
import json
import easygui as easygui
import tkinter as tk
import requests
import io
from PIL import Image,ImageTk
from urllib.request import urlopen

class sws:
    def webimage(url,title=None):
        imgd=tk.Tk()
        imgd.resizable(0,0)
        image_bytes = urlopen(url).read()
        # internal data file
        data_stream = io.BytesIO(image_bytes)
        # open as a PIL image object
        pil_image = Image.open(data_stream)
        # optionally show image info
        # get the size of the image
        w, h = pil_image.size
        # split off image file name
        fname = url.split('/')[-1]
        sf = "{} ({}x{})".format(fname, w, h)
        imgd.title(title+sf)
        # convert PIL image object to Tkinter PhotoImage object
        tk_image = ImageTk.PhotoImage(pil_image)
        # put the image on a typical widget
        label = tk.Label(imgd, image=tk_image, bg='brown')
        label.pack(padx=5, pady=5)
        imgd.mainloop()
    
    def textbox(text,title=None):
        root = tk.Tk()
        root.iconbitmap('')
        root.title(title)
        T = tk.Text(root, height=30, width=60)
        root.resizable(0, 0)
        T.pack()
        scroll = tk.Scrollbar()
        scroll.pack(side=tk.RIGHT,fill=tk.Y)
        T.pack(side=tk.LEFT,fill=tk.Y)
        scroll.config(command=T.yview)
        T.config(yscrollcommand=scroll.set)
        T.insert(tk.END,text)
        root.mainloop()

def main():
    try:
        ID = easygui.enterbox('输入作品ID',title="输入作品ID")
        URL = ('https://api.codemao.cn/creation-tools/v1/works/' + ID)
        resp = urllib.request.urlopen(URL)
        ele_json = json.loads(resp.read())
        sws.textbox(ele_json,title="Json片段")
        sws.webimage(ele_json['preview'],title="封面(Json.Preview)")
        sws.webimage(ele_json['screenshot_cover_url'],title="屏幕截图(Json.Screenshot_Cover_Url)")
        sws.textbox(ele_json['bcm_version'],title="Kitten编辑器版本(Json.bcm_version)")
        sws.textbox(ele_json['type'],title="Kitten编辑器版本(Json.Type)")
        sws.textbox(ele_json['description'],title="详情(Json.description)")
        sws.textbox(ele_json['operation'],title="操作说明(Json.operation)")
        sws.textbox(ele_json['player_url'],title="Player链接(Json.player_url)")
    except BaseException:
            easygui.exceptionbox(title="出错啦!")

main()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页