展开全部
有什么问题吗32313133353236313431303231363533e78988e69d8331333361303038 ,刚好之前写过一些关于py3 tk的东西,可以一起探讨一下,给你一个例子:import urllib, urllib.request
import os, re
from tkinter import *
import tkinter.ttk
import ctypes
import threading, time
def RunApp():
handler = None;
operator = "open";
fpath = "D:\SoftWare\Chrome\Chrome\chrome.exe";
param = '-user-data-dir="D:\SoftWare\Chrome\profil';
dirpath = 'D:\SoftWare\Chrome\Chrome';
ncmd = 1;
shell32 = ctypes.windll.LoadLibrary("shell32.dll");
shell32.ShellExecuteW(handler,operator,fpath,param,dirpath,ncmd);
def callbackfunc(blocknum, blocksize, totalsize):
'''回调函数
@blocknum: 已经下载的数据块
@blocksize: 数据块的大小
@totalsize: 远程文件的大小
'''
percent = 100.0 * blocknum * blocksize / totalsize
if percent > 100:
percent = 100
prb['value'] = percent
lbjd['text'] = '更新进度 %0.2f ' % percent + '%'
#print(percent)
def prbadd():
prb['value'] += 1
def Load():
time.sleep(0.5)
t1 = threading.Thread(target=down)
t1.start()
def down():
nfn = vel+'_chrome_installer.exe'
print('hehe')
urllib.request.urlretrieve(link,nfn,callbackfunc)
os.system('update.bat '+nfn)
#print('更新完成')
#os.system('PAUSE')
#os.system('''start D:\SoftWare\Chrome\Chrome\chrome.exe -user-data-dir="D:\SoftWare\Chrome\profil"''')
RunApp()
root.quit()
html = urllib.request.urlopen('http://down.tech.sina.com.cn/page/40975.html').read().decode('gbk')
t = re.search('(?<=down_load_url" href=")[^"]+(?=" target="_blank" class="f14b">正式版-)',html)
link = 'http://down.tech.sina.com.cn' + t.group(0)
title = html[html.index('
') + 7 : html.index('')]vel = title[title.rindex('/')+1:title.index('】') - 3]
ls = os.listdir('../Chrome/')
for fn in ls:
if fn.find('exe') == -1:
oldvel = fn
break
if oldvel != vel:
root = Tk()
root.title('Chrome更新工具')
# root.attributes("-toolwindow", 1)
lbjd = Label(root,text='更新进度')
lbjd.pack()
prb = tkinter.ttk.Progressbar(root, length=400, maximum=100.0, value=0)
prb.pack()
sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()
root.geometry('410x50+'+str(int((sw-410)/2))+'+'+str(int((sh-50)/2)))
#root.bind('',Load)
Load()
root.mainloop()
else:
#print('已经是最新版本')
RunApp()
#os.system('''start D:\SoftWare\Chrome\Chrome\chrome.exe -user-data-dir="D:\SoftWare\Chrome\profil"''')
#print(title)
这个是我自己更新chrome用的