|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import urllib.request
- import easygui as g
- title = '下载一只猫'
- msg = '请输入猫的尺寸'
- filelds =['宽:','高:']
- input1 = g.multenterbox(msg,title,filelds)
- url = 'http://placekitten.com/%s/%s' % (input1[0],input1[1])
- response = urllib.request.urlopen(url)
- cat_image = response.read()
- with open('cat.jpg','wb') as f:
- f.write(cat_image)
- g.filesavebox(default = 'cat.jpg',filetypes = ['.jpg'])
复制代码
就是保存不了指定的文件夹内
本帖最后由 Twilight6 于 2020-8-16 18:10 编辑
改成这样,你直接 with 而且 open 填 cat.jpg 只是写入当前文件夹下了
- import urllib.request
- import easygui as g
- title = '下载一只猫'
- msg = '请输入猫的尺寸'
- filelds =['宽:','高:']
- input1 = g.multenterbox(msg,title,filelds)
- url = 'http://placekitten.com/%s/%s' % (input1[0],input1[1])
- response = urllib.request.urlopen(url)
- cat_image = response.read()
- path = g.filesavebox(default = 'cat.jpg',filetypes = ['.jpg'])
- with open(path,'wb') as f:
- f.write(cat_image)
复制代码
|
|