commit six
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/python3
|
||||
import tkinter as tk
|
||||
import os
|
||||
from tkinter import ttk
|
||||
from custom_file_dialog import CustomFileDialog
|
||||
|
||||
@@ -9,22 +10,48 @@ class GlotzMol(tk.Tk):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.geometry('800x400')
|
||||
ttk.Label(text="Custodialog-teschdfeschda").grid(row=0, column=0)
|
||||
self.columnconfigure(1, weight=1)
|
||||
self.iso_path_entry = ttk.Entry(self)
|
||||
self.title("Custom File Dialog Test")
|
||||
|
||||
container = ttk.Frame(self, padding=10)
|
||||
container.pack(fill="both", expand=True)
|
||||
|
||||
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=15, pady=5, sticky="ew")
|
||||
ttk.Button(self, text="Öffnen", command=self.customtest).grid(
|
||||
row=2, column=0, padx=5, pady=5)
|
||||
row=1, column=0, columnspan=2, padx=(0, 10), pady=5, sticky="ew")
|
||||
|
||||
def customtest(self):
|
||||
dialog = CustomFileDialog(self, initial_dir="/home/punix/Downloads",
|
||||
filetypes=[("ISO files", "*.iso"), ("All files", "*.*")])
|
||||
path = dialog.get_selected_file()
|
||||
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")
|
||||
|
||||
if path:
|
||||
container.columnconfigure(0, weight=1)
|
||||
|
||||
def open_custom_dialog(self):
|
||||
# Initial directory can be anywhere, let's test with /backup
|
||||
initial_directory = "/backup" if os.path.exists(
|
||||
"/backup") else os.path.expanduser("~")
|
||||
|
||||
dialog = CustomFileDialog(self,
|
||||
initial_dir=initial_directory,
|
||||
filetypes=[("Audio-Dateien", "*.mp3 *.wav"),
|
||||
("Video-Dateien", "*.mkv *.mp4"),
|
||||
("ISO-Images", "*.iso"),
|
||||
("Alle Dateien", "*.*")])
|
||||
|
||||
# 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, path)
|
||||
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__":
|
||||
@@ -33,7 +60,7 @@ if __name__ == "__main__":
|
||||
style = ttk.Style(root)
|
||||
root.tk.call('source', f"{theme_path}/water.tcl")
|
||||
try:
|
||||
root.tk.call('set_theme', 'dark')
|
||||
root.tk.call('set_theme', 'light')
|
||||
except tk.TclError:
|
||||
pass
|
||||
root.mainloop()
|
||||
|
||||
Reference in New Issue
Block a user