python3开启mainloop线程_在自己的线程或进程中运行“mainloop()”?

您需要做的基本上是形成一个类(这是一个更好的实践)&在mainloop中调用该类from Tkinter import *

from tkFileDialog import *

import os.path

import shutil

import sys

import tempfile

from zipfile import ZipFile

import subprocess

class uiclass():

def __init__(self,root):

b = Button(root, text="Browse", command=self.callback)

w = Label(root, text="Please choose a .pages file to convert.")

w.pack()

b.pack()

def callback(self):

print "click!"

global y

y = askopenfilename(parent=root, defaultextension=".pages")

self.view_file(y)

def view_file(self,filepath):

subprocess.Popen(filepath, shell=True).wait()

PREVIEW_PATH = 'QuickLook/Preview.pdf' # archive member path

#pages_file = raw_input('Enter the path to the .pages file in question: ')

pages_file = y

pages_file = os.path.abspath(pages_file)

filename, file_extension = os.path.splitext(pages_file)

if file_extension == ".pages":

tempdir = tempfile.gettempdir()

temp_filename = os.path.join(tempdir, PREVIEW_PATH)

with ZipFile(pages_file, 'r') as zipfile:

zipfile.extract(PREVIEW_PATH, tempdir)

if not os.path.isfile(temp_filename): # extract failure?

sys.exit('unable to extract {} from {}'.format(PREVIEW_PATH, pages_file))

final_PDF = filename + '.pdf'

shutil.copy2(temp_filename, final_PDF) # copy and rename extracted file

# delete the temporary subdirectory created (along with pdf file in it)

shutil.rmtree(os.path.join(tempdir, os.path.split(PREVIEW_PATH)[0]))

print('Check out the PDF! It\'s located at "{}".'.format(final_PDF))

self.view_file(final_PDF) # see Bonus below

else:

sys.exit('Sorry, that isn\'t a .pages file.')

if __name__ == '__main__':

root = Tk()

uiclass(root)

root.wm_title("Pages to PDF")

root.mainloop()

调用方法本身中的其他方法。在

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值