是否可以在两个按钮下制作进度条

2024-04-19 06:09:31 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有可能在“水+”和“水-”的两个按钮下做一个Progressbar,这样当我按Button水+Progressbar处理一步,当我按Button水-Progressbar向后移动一步。你知道吗

谢谢大家。你知道吗


Tags: button按钮progressbar
1条回答
网友
1楼 · 发布于 2024-04-19 06:09:31

是的,可以将Progressbar设置为过程,具体取决于Button按下或触发的事件。你知道吗

这是一个示例代码。

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

progressbar = ttk.Progressbar(root, length=200, maximum=10, value=5)
progressbar.grid(row=1)

process = tk.IntVar(value=5)
def add_water():
    if process.get() < progressbar['maximum']:
        process.set( process.get() + 1)
        progressbar['value'] = process.get()

def sub_water():
    if process.get() > 0:
        process.set( process.get() - 1)
        progressbar['value'] = process.get()

add = ttk.Button(root, text='Water +', command=add_water)
sub = ttk.Button(root, text='Water -', command=sub_water)

label = ttk.Label(root, textvariable=process)

label.grid(row=0)
add.grid(row=0, sticky='e')
sub.grid(row=0, sticky='w')

root.mainloop()

enter image description here

相关问题 更多 >