svg-processor/gui/status_bar.py
2025-05-16 18:15:31 +04:00

67 lines
1.8 KiB
Python

import tkinter as tk
from tkinter import ttk
class StatusBar(ttk.Frame):
"""Status bar component for displaying application status."""
def __init__(self, parent, **kwargs):
"""
Initialize the Status Bar.
Args:
parent: The parent widget.
**kwargs: Additional arguments for ttk.Frame.
"""
super().__init__(parent, **kwargs)
self.status_var = tk.StringVar()
self._create_widgets()
def _create_widgets(self):
"""Create the widgets for the status bar."""
self.status_label = ttk.Label(
self,
textvariable=self.status_var,
anchor=tk.W,
padding=(5, 2)
)
self.status_label.pack(side=tk.LEFT, fill=tk.X, expand=True)
def set_status(self, message):
"""Set the status message.
Args:
message (str): The status message to display.
"""
self.status_var.set(message)
def clear_status(self):
"""Clear the status message."""
self.status_var.set("")
# Example usage (for testing)
if __name__ == '__main__':
root = tk.Tk()
root.title("Status Bar 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 status bar
status_bar = StatusBar(root)
status_bar.pack(side=tk.BOTTOM, fill=tk.X)
# Test buttons
def set_status():
status_bar.set_status("Test status message")
def clear_status():
status_bar.clear_status()
ttk.Button(root, text="Set Status", command=set_status).pack(pady=5)
ttk.Button(root, text="Clear Status", command=clear_status).pack(pady=5)
root.mainloop()