Struktur: Integriere CustomFileDialog und AnimatedIcon
Die Komponenten des CustomFileDialog wurden aus einem separaten Repository importiert und in ein eigenes Verzeichnis verschoben. Die Test-Datei 'mainwindow.py' wurde entfernt. 'animated_icon.py' wurde als gemeinsam genutzte Komponente im Stammverzeichnis platziert.
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
import tkinter as tk
|
||||
import os
|
||||
from tkinter import ttk
|
||||
from custom_file_dialog import CustomFileDialog
|
||||
|
||||
|
||||
class GlotzMol(tk.Tk):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.geometry('800x400')
|
||||
self.title("Custom File Dialog Test")
|
||||
|
||||
container = ttk.Frame(self, padding=10)
|
||||
container.pack(fill="x", anchor="n")
|
||||
|
||||
ttk.Label(container, text="Ausgewählte Datei:").grid(
|
||||
row=0, column=0, sticky="w")
|
||||
|
||||
self.iso_path_entry = ttk.Entry(container)
|
||||
self.iso_path_entry.grid(
|
||||
row=1, column=0, columnspan=2, padx=(0, 10), pady=5, sticky="ew")
|
||||
|
||||
self.open_button = ttk.Button(
|
||||
container, text="Datei auswählen...", command=self.open_custom_dialog)
|
||||
self.open_button.grid(row=1, column=2, pady=5, sticky="e")
|
||||
|
||||
container.columnconfigure(0, weight=1)
|
||||
|
||||
def open_custom_dialog(self):
|
||||
|
||||
dialog = CustomFileDialog(self,
|
||||
initial_dir=os.path.expanduser("~"),
|
||||
filetypes=[("All Files", "*.*"),
|
||||
("Wireguard config Files", "*.conf")
|
||||
])
|
||||
|
||||
# This is the crucial part: wait for the dialog to be closed
|
||||
self.wait_window(dialog)
|
||||
|
||||
# Now, get the result
|
||||
selected_path = dialog.get_selected_file()
|
||||
|
||||
if selected_path:
|
||||
self.iso_path_entry.delete(0, tk.END)
|
||||
self.iso_path_entry.insert(0, selected_path)
|
||||
print(f"Die ausgewählte Datei ist: {selected_path}")
|
||||
else:
|
||||
print("Keine Datei ausgewählt.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
root = GlotzMol()
|
||||
theme_path = '/usr/share/TK-Themes'
|
||||
style = ttk.Style(root)
|
||||
root.tk.call('source', f"{theme_path}/water.tcl")
|
||||
try:
|
||||
root.tk.call('set_theme', 'dark')
|
||||
except tk.TclError:
|
||||
pass
|
||||
root.mainloop()
|
Reference in New Issue
Block a user