如何将进度条连接到 Tkinter 中的函数?
进度条有助于可视化正在运行的进程的状态。我们已经使用并与许多进度条进行了交互,例如获取从互联网下载文件的进度、在本地系统上加载文件,等等。
假设我们希望在应用程序中创建进度条并连接它。我们将使用 ProgressBar(win, options) 方法创建一个全宽进度条。可以通过启用和禁用它的按钮来配置它。
示例代码
#Import the required Libraries
from tkinter import *
from tkinter import ttk
import time
#Create an instance of tkinter frame
win= Tk()
#Set the geometry
win.geometry("750x250")
#Define a function to Show a Progress Bar
#Create a ProgressBar in a function
def run_progress():
my_progress= ttk.Progressbar(win, orient= HORIZONTAL, length= 500, mode= 'determinate')
my_progress['value']+=500
my_progress.pack(pady=40)
button.config(state= "disable")
#Create a Button
button=ttk.Button(win, text= "Run",command= run_progress)
button.place(x= 340, y= 100)
win.mainloop()现在运行上述代码以显示包含进度条的窗口。
输出
在给定的输出中,如果单击“运行”按钮,将开始运行进度条。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP