I'm curious about how to retrieve specific windows and change their order in Python. Can you provide some guidance?
I attempted to use PyGetWindows to retrieve specific windows in a game and create orders based on a GUI where I entered numbers for the order, but I encountered difficulties.
here is my code which recovers the current windows but I don't know how to manage the order of the windows
import pygetwindow as gw
import tkinter as tk
def get_dofus_window_names():
open_windows = gw.getAllTitles()
dofus_window_names = []
for title in open_windows:
index = title.find(" - Dofus")
if index != -1:
dofus_name = title[:index]
dofus_window_names.append(dofus_name)
return sorted(dofus_window_names) # Trie les noms par ordre alphabétique
def update_labels():
dofus_names = get_dofus_window_names()
label_text.set("\n".join(dofus_names))
# Crée une fenêtre tkinter
root = tk.Tk()
root.minsize(width=300, height=100)
root.resizable(False, False)
# Crée un label pour afficher les noms de fenêtres
label_text = tk.StringVar()
label = tk.Label(root, textvariable=label_text)
label.pack()
# Crée un bouton pour mettre à jour les noms de fenêtres
update_button = tk.Button(root, text="Mettre à jour", command=update_labels)
update_button.pack()
# Affiche les noms de fenêtres triés au démarrage
update_labels()
# Lance la boucle principale de l'interface graphique
root.mainloop()