繁体   English   中英

如何在 python 中实现 tkinter 进度条,用户可以在相同的 position 中暂停和重新启动进度条?

[英]How to implement a tkinter progress bar in python where the user can pause and restart the progress bar at the same position it was stopped?

这是我到目前为止的代码,理想情况下,我希望它暂停,直到用户再次单击开始。 任何帮助表示赞赏:!! 非常感谢:) <3

from tkinter import *
from tkinter import ttk
import time
from threading import *
import threading
import _thread

def start():
   w.start()

def stop():
   time.sleep(10)


def stopfunc():
    _thread.start_new_thread(stop,())

window = Tk()

w = ttk.Progressbar(window)
w.pack()
button1 = ttk.Button(window, text = 'start', command = start)
button1.pack()
button2 = ttk.Button(window, text = 'stop', command = stopfunc)
button2.pack()
window.mainloop()

variable参数设置为控制变量,例如IntVar

from tkinter import *
from tkinter import ttk


def start():
    
   w.start()

def stopfunc():
    w.stop()
    #var.set(var.get())

def reset():
    var.set(0)

window = Tk()

var = IntVar()

w = ttk.Progressbar(window, variable=var)
w.pack()
button1 = ttk.Button(window, text = 'start', command = start)
button1.pack()
button2 = ttk.Button(window, text = 'stop', command = stopfunc)
button2.pack()

button2 = ttk.Button(window, text = 'reset', command = reset)
button2.pack()


window.mainloop()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM