Tkinter使用Progressbar创建和管理进度条的操作代码

  import tkinter as tk

  from tkinter.ttk import Progressbar

  class Simulate_Waiting_State:

  def __init__(self):

  self.root = tk.Tk()

  self.root.title('进度条下载演示')

  self.root.geometry("300x150+1100+150")

  self.interface()

  def interface(self):

  # 创建进度条

  self.progress_bar = Progressbar(self.root, length=200, mode="indeterminate")

  # 创建按钮

  self.start_button = tk.Button(self.root, text="开始", command=self.start_progress)

  self.stop_button = tk.Button(self.root, text="停止", command=self.stop_progress)

  # 将进度条和按钮放置在窗口中

  self.progress_bar.grid(row=0, column=1, pady=20, padx=50, columnspan=100)

  self.start_button.grid(row=1, column=1, padx=75)

  self.stop_button.grid(row=1, column=3)

  def start_progress(self):

  self.progress_bar.start()

  def stop_progress(self):

  self.progress_bar.stop()

  if __name__ == '__main__':

  run = Simulate_Waiting_State()

  run.root.mainloop()

  import tkinter as tk

  from tkinter.ttk import Progressbar

  class Simulate_Waiting_State:

  def __init__(self):

  self.root = tk.Tk()

  self.root.title('进度条下载演示')

  self.root.geometry("300x150+1100+150")

  self.interface()

  def interface(self):

  # 创建进度条

  self.progress_bar = Progressbar(self.root, length=200, mode="indeterminate")

  # 创建按钮

  self.start_button = tk.Button(self.root, text="开始", command=self.start_progress)

  self.stop_button = tk.Button(self.root, text="停止", command=self.stop_progress)

  # 将进度条和按钮放置在窗口中

  self.progress_bar.grid(row=0, column=1, pady=20, padx=50, columnspan=100)

  self.start_button.grid(row=1, column=1, padx=75)

  self.stop_button.grid(row=1, column=3)

  def start_progress(self):

  self.progress_bar.start()

  def stop_progress(self):

  self.progress_bar.stop()

  if __name__ == '__main__':

  run = Simulate_Waiting_State()

  run.root.mainloop()