这篇文章主要介绍了Python tkinter模版代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
代码如下
import tkinterimport timeimport threadingfrom tkinter import ttkevent = threading.Event()once=0def start(): global once if once==1: # event.set() # print('继续') pass else: event.set() t1 = threading.Thread(target=thread) # print(threading.currentThread()) //获取线程id t1.setDaemon(True) # validate() t1.start() print("开始") once+=1def stop(): event.clear() print('暂停')def conti(): event.set() print('继续') def main(): try: print(s1.get(),s2.get()) for i in range(0, 30): mpb["value"] = i text.see(tkinter.END) # 一直查看文本的最后位置~ text.insert('end', "验证不通过,请查看!" + str(i) + "/r/n") # scale.config(mode='determinate', maximum=11.0, value=i) text.update() # 一直更新输出 print(i) time.sleep(0.1) event.wait() window.update() text.insert('end', "程序运行完成!" + "/r/n") text.update() text.see(tkinter.END) print("验证不通过!") pass except: pass def thread(): # while True: main() window = tkinter.Tk()window.title('测试') # l1=tkinter.Label(text="word输出文件路径")l1.grid(row=0,column=0) # e1=tkinter.Entry("")s1 = tkinter.StringVar()entry1 = tkinter.Entry(window, textvariable=s1)entry1.grid(row=0,column=1) l2=tkinter.Label(text="Excel文件路径")l2.grid(row=1,column=0) # e2=tkinter.Entry("")s2 = tkinter.StringVar()entry2 = tkinter.Entry(window, textvariable=s2)entry2.grid(row=1,column=1) i=0mpb = ttk.Progressbar(window, orient="horizontal", length=200, value=0,mode="determinate")mpb.grid(row=2,column=0,columnspan=2) button1=tkinter.Button(window,text='开始',command=start)button1.grid(row=0,column=2)button2=tkinter.Button(window,text='暂停',command=stop)button2.grid(row=1,column=2)button3=tkinter.Button(window,text='继续',command=conti)button3.grid(row=2,column=2) from tkinter import scrolledtext # 导入滚动文本框的模块 scrolW = 50 # 设置文本框的长度scrolH = 18 # 设置文本框的高度text = scrolledtext.ScrolledText(window, width=scrolW, height=scrolH, wrap=tkinter.WORD)text.grid(row=10, columnspan=8, sticky=tkinter.E) tkinter.mainloop()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林站长站。
新闻热点
疑难解答