tkinter调用线程后UI卡死?
python写了个自动下载ftp文件程序,在tkinter里面加了个按钮,点击执行下载,执行过程中把信息打印到tkinter主界面的text框里,执行过程会卡死,可是我明明用的线程啊,上代码:
class DownloadFtp(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.ftp = FTP()
self.timeout = 30
self.port = 21
self.host = '………………'
self.user = '……'
self.password = '……'
def ftp_connect(self):
try:
self.ftp.connect(self.host, self.port, self.timeout)
self.ftp.login(self.user, self.password)
text.insert(END, self.ftp.getwelcome() + '\n')
self.ftp.cwd('……/……')
except:
traceback.print_exc()
download_ftp()
def start_download(self):
self.ftp_connect()
ftp_list = self.ftp.nlst()
for name in ftp_list:
text.insert(END, u'获得文件:' + name.decode('gb2312')+'\n')
if not os.path.exists('py_auto_download/' + name):
path = 'py_auto_download/' + name
f = open(path, 'wb')
filename = 'RETR ' + name
text.insert(END, u'正在下载:' + name.decode('gb2312')+'\n')
self.ftp.retrbinary(filename, f.write)
else:
text.insert(END, u'文件或者文件夹已存在,忽略\n')
self.ftp.quit()
def button_ftp():
if not os.path.exists('py_auto_download'):
os.makedirs('py_auto_download')
my_ftp = DownloadFtp()
my_ftp.start()
my_ftp.start_download()
if __name__ == '__main__':
root = Tkinter.Tk()
root.title(u'自助操作端升级')
root.geometry('300x400')
root.resizable(width=False, height=False)
text = Text(root)
text.pack(side=TOP)
frameButton = Frame(root)
frameLButton = Frame(frameButton)
buttonESQL = Button(frameLButton, text=u'升级本地SQL数据库', command=button_exec_sql)
buttonESQL.pack(side=LEFT)
frameLButton.pack(side=LEFT)
frameRButton = Frame(frameButton)
buttonFTP = Button(frameRButton, text=u'下载自助操作端升级包', command=button_ftp)
buttonFTP.pack(side=RIGHT)
frameRButton.pack(side=RIGHT)
frameButton.pack()
root.mainloop()
相关阅读:
求大神指点:点击form只提交form中input的一部分
微信开放平台的扫码登陆问题
Typecho如何单纯输出上一篇和下一篇文章的链接和标题。
bootstrap栅格3列变形了,怎么解决?
关于windows上启动resin的问题
ng-bind-html 输出的内容中含有,并且可以输入,怎样可以禁止对输入
前端如何实现HTML代码的复用?
json字符串错误定位
typecho 后台无法登陆
atg接口是什么玩意?
NSDateFormatter stringFromDate格式化的值有时返回不符合预期的结果
phpstorm如何对项目(thinkphp)中的视图页进行调试呢?
数据库在添加新功能的时候,如果需要改动数据库字段一般如何迁移数据
background-position
希望短信验证码能返回正常的statuscode
#import 和 #import "UIKit.h"有什么区别?
怎么能在Sublime里输入常用片段,同时仅修改部分信息?
微信公众平台开发中的微信支付,是否可以做类似于商户付款的流程?
七牛SDK 7.x使用了Photo.framework(iOS8及以上系统上可用),导致在iOS7系统上无法使用,请问如何解决
移动端单位rem和px混合使用问题