我想在一个进度条循环后打开注释文件,无法理解互联网上给出的解决方案,因为我的代码很简单,所以需要简单的答案,因为我在Tkinter非常初学者< / p>
from tkinter import *
import tkinter.ttk as ttk
from tkinter import Label
import time
root = Tk()
root.geometry('350x215')
root.title("WELCOME")
root.configure(bg='skyblue')
label1=Label(root,text="Spam Checker",font=
('Constantia',30),bg='skyblue').place(x=50,y=50)
label2=Label(root,text="(ML Approach)",font=
(None,16),bg='skyblue').place(x=100,y=100)
pb = ttk.Progressbar(root,length=350, orient='horizontal',
mode='determinate')
pb.place(y=190)
pb.maximum=100
pb.start()
""""def openwindow():
with open('main1.py') as source_file:
`enter code here`exec(source_file.read())
"""
root.mainloop()
答案 0 :(得分:0)
首先,您必须将变量与ProgressBar相关联:
progress_var = IntVar()
pb = ttk.Progressbar(root, length=350, variable=progress_var)
然后,每次更新进度条时,您都可以使用trace
方法运行函数,如here所述。
当进度条达到100时,其值将重置为0.因此当函数检测到该值为0时,它会停止进度条并调用openwindow
函数:
def on_progress_bar_updated(*args):
# when the progress bar reaches 100, it wraps around to 0
if progress_var.get() == 0:
pb.stop()
openwindow()
progress_var.trace('w', on_progress_bar_updated)
pb.start()