首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Python 3和Tkinter制作GUI文件下载器

用Python 3和Tkinter制作GUI文件下载器
EN

Stack Overflow用户
提问于 2018-09-12 20:39:50
回答 2查看 4.7K关注 0票数 0

(我正在使用python 3.6.6,如果这对任何人重要的话)

我正在为一个游戏的GUI安装程序,目前是在私人阿尔法,并不断更新。

我已经做了一个控制台版本:

代码语言:javascript
复制
from tqdm import tqdm
import requests, os, sys, zipfile, shutil, subprocess

chunk_size = 1024
url = "{LINK TO FILE YOU WANT TO DOWNLOAD}"
r = requests.get(url, stream = True)
total_size = int(r.headers['content-length'])


print("Are you sure you want to download the newest version of RFMP?")
print("y/n", end=': ')

answer = input()

while True:
    if answer == 'y':
        if os.path.exists("RFMB6_WINDOWS"):
            print('')
            print('')
            print('Removing old RFMP files...')
            subprocess.check_call(('attrib -R ' + 'RFMB6_WINDOWS' + '\\* /S').split())
            shutil.rmtree('RFMB6_WINDOWS')
            print('')
            print('Removed old files.')
            break
        else:
            break
    elif answer == 'n':
         sys.exit()

    else:
         print("That is not a valid answer, please answer with y/n.")
         answer = input()


print('')
print('')
print('Downloading:')
with open('RFMB6_WINDOWS.zip', 'wb') as f:
    for data in tqdm(iterable = r.iter_content(chunk_size = chunk_size), total = total_size/chunk_size, unit = 'KB'):
             f.write(data)
print('')
print("Download Complete.")
print('')
print('')

print("Would you like to extract it?")
print("y/n", end=': ')
answer2 = input()

while True:
    if answer2 == 'y':
            print('')
            print('')
            print('Extracting...')
            zip_ref = zipfile.ZipFile("RFMB6_WINDOWS.zip", 'r')
            zip_ref.extractall("RFMB6_WINDOWS")
            zip_ref.close()
            print('')
            print('Extraction Complete')
            print('')
            print('')
            print('Cleaning up...')
            os.remove("RFMB6_WINDOWS.zip")
            print('')
            print('Done! You have succesfully installed the newest version of the Ravenfield Multiplayer Private Alpha.')
            break   
    elif answer2 == 'n':
            print('')
            print('Done! You have succesfully downloaded the newest Zip of the Ravenfield Multiplayer Private Alpha.')
            break
    else:
            print("That is not a valid answer, please answer with y/n.")
            answer = input()


os.system('pause')

我将只使用这个下载一个特定的链接,所以忽略url变量。

当我点击一个显示“下载”的按钮时,我正在尝试制作一个做同样事情的GUI。我想要制作一个进度条和一个文本框来告诉您正在进行什么,例如下载、提取等。我不需要目录选项。我只需要它下载任何地方的文件,并删除旧的文件,如果它仍然在那里。

因此,我的问题是:我如何学习如何做到这一点?我看过tkinter教程和其他问题,但我只找到python 2的内容,或者是用来修改和调用自己工作的东西。我正在寻找的是链接和/或例子,可以告诉我如何创建这样的东西。提前感谢任何帮助我的人。

在编码方面,我是个菜鸟,所以不管你解释什么,都要彻底地去做。

为了运行控制台应用程序,您需要通过终端运行它,并在'url‘变量中添加您自己的链接。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-09-13 04:03:16

看看PySimpleGUI。您可以轻松地构建带有下载按钮、输出窗口和进度条的布局。如果你遇到麻烦,请到GitHub前发布一个问题。

票数 2
EN

Stack Overflow用户

发布于 2018-09-12 20:46:23

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52303146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档