71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk
|
|
|
|
class ProgressFrame(ttk.Frame):
|
|
"""Frame for displaying progress information."""
|
|
|
|
def __init__(self, parent, **kwargs):
|
|
"""
|
|
Initialize the Progress Frame.
|
|
|
|
Args:
|
|
parent: The parent widget.
|
|
**kwargs: Additional arguments for ttk.Frame.
|
|
"""
|
|
super().__init__(parent, **kwargs)
|
|
self._create_widgets()
|
|
|
|
def _create_widgets(self):
|
|
"""Create the widgets for the progress frame."""
|
|
# Create progress bar
|
|
self.progress = ttk.Progressbar(
|
|
self,
|
|
mode='indeterminate',
|
|
length=200
|
|
)
|
|
self.progress.pack(fill=tk.X, expand=True, padx=5, pady=5)
|
|
|
|
def start(self):
|
|
"""Start the progress bar."""
|
|
self.progress.start()
|
|
|
|
def stop(self):
|
|
"""Stop the progress bar."""
|
|
self.progress.stop()
|
|
|
|
def reset(self):
|
|
"""Reset the progress bar."""
|
|
self.progress.stop()
|
|
self.progress['value'] = 0
|
|
|
|
# Example usage (for testing)
|
|
if __name__ == '__main__':
|
|
root = tk.Tk()
|
|
root.title("Progress Frame Test")
|
|
root.geometry("400x100")
|
|
|
|
# Style for testing
|
|
style = ttk.Style()
|
|
style.theme_use('clam')
|
|
style.configure('TFrame', background='#f0f0f0')
|
|
style.configure('TLabel', background='#f0f0f0')
|
|
|
|
# Create and pack the progress frame
|
|
progress_frame = ProgressFrame(root)
|
|
progress_frame.pack(fill=tk.X, expand=True, padx=10, pady=10)
|
|
|
|
# Test buttons
|
|
def start_progress():
|
|
progress_frame.start()
|
|
|
|
def stop_progress():
|
|
progress_frame.stop()
|
|
|
|
def reset_progress():
|
|
progress_frame.reset()
|
|
|
|
ttk.Button(root, text="Start", command=start_progress).pack(side=tk.LEFT, padx=5)
|
|
ttk.Button(root, text="Stop", command=stop_progress).pack(side=tk.LEFT, padx=5)
|
|
ttk.Button(root, text="Reset", command=reset_progress).pack(side=tk.LEFT, padx=5)
|
|
|
|
root.mainloop() |