Alles anzeigenDer 14. Teil einer Einführung in die Python3-Bibliothek Tkinter und der lange Weg zum perfekten GUI.
Nach so viel harter Denkarbeit haben wir es uns verdient, auch mal etwas entspannter zu arbeiten. Linux-Desktops und eigentlich IT allgemein folgen immer einer Logik, einem Schema. Heute soll es um das Auslesen des Icon-Themes gehen. Den Grundstein dafür haben wir schon gelegt, indem wir Funktionen geschrieben haben, um das Desktop-Theme auszulesen. Da das alles, wie schon erwähnt, einem Schema folgt, müssen wir heute nur Copy & Paste betreiben und ein paar Begriffe/Variablen ändern.
[Blockierte Grafik: https://gnulinux.ch/bl-content…vom2024-10-3111-19-39.png]
KDE
Aus unserer Funktion vom letzten Mal
(get_kde_theme_new())wirddef get_kde_icons().Die Parameter
'--group', 'KDE', '--key', 'LookAndFeelPackagewerden zu'--group', 'Icons', '--key', 'Theme'.Code# Ließt die KDE-Icons aus@@@WCF_PRE_LINEBREAK@@@def get_kde_icons():@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['plasmashell', '--version'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ plasma_version = result.stdout.strip()@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if "plasmashell 5." in plasma_version:@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['kreadconfig5', '--file', '~/.config/kdeglobals', '--group', 'Icons', '--key', 'Theme'],stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) @@@WCF_PRE_LINEBREAK@@@ output = result.stdout.strip()@@@WCF_PRE_LINEBREAK@@@ return output@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if "plasmashell 6." in plasma_version:@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['kreadconfig6', '--file', '~/.config/kdeglobals', '--group', 'Icons', '--key', 'Theme'],stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) @@@WCF_PRE_LINEBREAK@@@ output = result.stdout.strip()@@@WCF_PRE_LINEBREAK@@@ return output@@@WCF_PRE_LINEBREAK@@@Der Rest
Wir schnappen uns die bereits bestehende Funktion
def get_desktop_theme()und kopieren sie. Auch hier benennen wir einiges um und die Funktion wird zuget_desktop_icons. Für alle auf Gnome-basierenden Desktops ändern wir den Key zuicon-theme.In XFCE lesen wir die Icons so aus:
Codeif get_desktop_environment() == "XFCE":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['xfconf-query', '-c', 'xsettings', '-p'"/Net/IconThemeName","-s",],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )
Im Falle von KDE:
Codedef get_desktop_icons():@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "GNOME":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.gnome.desktop.interface', 'icon-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "CINNAMON":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.cinnamon.desktop.interface', 'icon-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'") @@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "MATE":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.mate.interface', 'icon-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "XFCE":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['xfconf-query', '-c', 'xsettings', '-p'"/Net/IconThemeName","-s",],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "PI-WAYFIRE":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.gnome.desktop.interface', 'icon-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "KDE":@@@WCF_PRE_LINEBREAK@@@ return get_kde_icons()@@@WCF_PRE_LINEBREAK@@@Um das Ausgelesene auch anzuzeigen benötigen wir ein neues Label:
Codeicon_theme_label = tk.Label(stat_frame,text=f"Icons: {get_desktop_icons()}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@icon_theme_label.pack(anchor=tk.NW)Der ganze Code
Python## Teil 14 ###@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@import tkinter as tk@@@WCF_PRE_LINEBREAK@@@from PIL import Image, ImageTk@@@WCF_PRE_LINEBREAK@@@import os@@@WCF_PRE_LINEBREAK@@@import socket@@@WCF_PRE_LINEBREAK@@@import distro@@@WCF_PRE_LINEBREAK@@@import platform@@@WCF_PRE_LINEBREAK@@@import psutil@@@WCF_PRE_LINEBREAK@@@import datetime@@@WCF_PRE_LINEBREAK@@@import subprocess@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Ließt den Desktop aus@@@WCF_PRE_LINEBREAK@@@def get_desktop_environment():@@@WCF_PRE_LINEBREAK@@@ xdg_current_desktop = os.environ.get("XDG_CURRENT_DESKTOP","").lower()@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if xdg_current_desktop == "x-cinnamon" or xdg_current_desktop == "cinnamon":@@@WCF_PRE_LINEBREAK@@@ return "CINNAMON"@@@WCF_PRE_LINEBREAK@@@ elif xdg_current_desktop == "unity":@@@WCF_PRE_LINEBREAK@@@ return "UNITY"@@@WCF_PRE_LINEBREAK@@@ elif xdg_current_desktop == "ubuntu:gnome":@@@WCF_PRE_LINEBREAK@@@ return "GNOME"@@@WCF_PRE_LINEBREAK@@@ elif "gnome" in xdg_current_desktop:@@@WCF_PRE_LINEBREAK@@@ return "GNOME"@@@WCF_PRE_LINEBREAK@@@ elif "plasma" == xdg_current_desktop or "kde" == xdg_current_desktop:@@@WCF_PRE_LINEBREAK@@@ return "KDE"@@@WCF_PRE_LINEBREAK@@@ elif "xfce" == xdg_current_desktop:@@@WCF_PRE_LINEBREAK@@@ return "XFCE"@@@WCF_PRE_LINEBREAK@@@ elif os.environ.get("DESKTOP_SESSION", "").lower() == "lxde-pi-wayfire":@@@WCF_PRE_LINEBREAK@@@ return "PI-WAYFIRE"@@@WCF_PRE_LINEBREAK@@@ elif "mate" == xdg_current_desktop:@@@WCF_PRE_LINEBREAK@@@ return "MATE"@@@WCF_PRE_LINEBREAK@@@ else:@@@WCF_PRE_LINEBREAK@@@ return "Unknown"@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Ließt das KDE Theme aus@@@WCF_PRE_LINEBREAK@@@def get_kde_theme_new():@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['plasmashell', '--version'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ plasma_version = result.stdout.strip()@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if "plasmashell 5." in plasma_version:@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['kreadconfig5', '--file', '~/.config/kdeglobals', '--group', 'KDE', '--key', 'LookAndFeelPackage'],stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) @@@WCF_PRE_LINEBREAK@@@ output = result.stdout.strip()@@@WCF_PRE_LINEBREAK@@@ return output@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if "plasmashell 6." in plasma_version:@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['kreadconfig6', '--file', '~/.config/kdeglobals', '--group', 'KDE', '--key', 'LookAndFeelPackage'],stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) @@@WCF_PRE_LINEBREAK@@@ output = result.stdout.strip()@@@WCF_PRE_LINEBREAK@@@ return output@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Ließt die KDE-Icons aus@@@WCF_PRE_LINEBREAK@@@def get_kde_icons():@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['plasmashell', '--version'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ plasma_version = result.stdout.strip()@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if "plasmashell 5." in plasma_version:@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['kreadconfig5', '--file', '~/.config/kdeglobals', '--group', 'Icons', '--key', 'Theme'],stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) @@@WCF_PRE_LINEBREAK@@@ output = result.stdout.strip()@@@WCF_PRE_LINEBREAK@@@ return output@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if "plasmashell 6." in plasma_version:@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['kreadconfig6', '--file', '~/.config/kdeglobals', '--group', 'Icons', '--key', 'Theme'],stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) @@@WCF_PRE_LINEBREAK@@@ output = result.stdout.strip()@@@WCF_PRE_LINEBREAK@@@ return output@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@#print(get_kde_icons())@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Ließt das DE-Theme aus@@@WCF_PRE_LINEBREAK@@@def get_desktop_theme():@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "GNOME":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.gnome.desktop.interface', 'gtk-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "CINNAMON":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.cinnamon.desktop.interface', 'gtk-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'") @@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "MATE":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.mate.interface', 'gtk-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "XFCE":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['xfconf-query', '-c', 'xsettings', '-p','/Net/ThemeName'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "PI-WAYFIRE":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.gnome.desktop.interface', 'gtk-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "KDE":@@@WCF_PRE_LINEBREAK@@@ return get_kde_theme_new()@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@def get_desktop_icons():@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "GNOME":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.gnome.desktop.interface', 'icon-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "CINNAMON":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.cinnamon.desktop.interface', 'icon-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'") @@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "MATE":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.mate.interface', 'icon-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "XFCE":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['xfconf-query', '-c', 'xsettings', '-p'"/Net/IconThemeName","-s",],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "PI-WAYFIRE":@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(['gsettings', 'get', 'org.gnome.desktop.interface', 'icon-theme'],capture_output=True,text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@ return result.stdout.strip().strip("'")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ if get_desktop_environment() == "KDE":@@@WCF_PRE_LINEBREAK@@@ return get_kde_icons()@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Ließt den Window-Manager aus@@@WCF_PRE_LINEBREAK@@@def get_window_manager_name():@@@WCF_PRE_LINEBREAK@@@ try:@@@WCF_PRE_LINEBREAK@@@ result = subprocess.run(@@@WCF_PRE_LINEBREAK@@@ ["wmctrl", "-m"], capture_output=True, text=True, check=True@@@WCF_PRE_LINEBREAK@@@ )@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ output_lines = result.stdout.strip().split("\n")@@@WCF_PRE_LINEBREAK@@@ for line in output_lines:@@@WCF_PRE_LINEBREAK@@@ if line.startswith("Name: "):@@@WCF_PRE_LINEBREAK@@@ window_manager_name = line.split("Name: ")[1]@@@WCF_PRE_LINEBREAK@@@ if window_manager_name == "GNOME Shell":@@@WCF_PRE_LINEBREAK@@@ return "Mutter"@@@WCF_PRE_LINEBREAK@@@ return window_manager_name@@@WCF_PRE_LINEBREAK@@@ except subprocess.CalledProcessError as e:@@@WCF_PRE_LINEBREAK@@@ print(f"Error running wmctrl: {e}")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Macht die RAM-Größe lesbar@@@WCF_PRE_LINEBREAK@@@def get_size(bytes, suffix="B"):@@@WCF_PRE_LINEBREAK@@@ """@@@WCF_PRE_LINEBREAK@@@ Scale bytes to its proper format@@@WCF_PRE_LINEBREAK@@@ e.g:@@@WCF_PRE_LINEBREAK@@@ 1253656 => '1.20MB'@@@WCF_PRE_LINEBREAK@@@ 1253656678 => '1.17GB'@@@WCF_PRE_LINEBREAK@@@ """@@@WCF_PRE_LINEBREAK@@@ factor = 1024@@@WCF_PRE_LINEBREAK@@@ for unit in ["", "K", "M", "G", "T", "P"]:@@@WCF_PRE_LINEBREAK@@@ if bytes < factor:@@@WCF_PRE_LINEBREAK@@@ return f"{bytes:.2f}{unit}{suffix}"@@@WCF_PRE_LINEBREAK@@@ bytes /= factor@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Findet die Auflösung heraus@@@WCF_PRE_LINEBREAK@@@def get_screen_size():@@@WCF_PRE_LINEBREAK@@@ screen_width = root.winfo_screenwidth()@@@WCF_PRE_LINEBREAK@@@ screen_height = root.winfo_screenheight()@@@WCF_PRE_LINEBREAK@@@ return f"{screen_width}x{screen_height}"@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@def get_sys_uptime():@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ # System-Startzeit ermitteln@@@WCF_PRE_LINEBREAK@@@ boot_time_timestamp = psutil.boot_time()@@@WCF_PRE_LINEBREAK@@@ boot_time = datetime.datetime.fromtimestamp(boot_time_timestamp)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ # Aktuelle Zeit@@@WCF_PRE_LINEBREAK@@@ now = datetime.datetime.now()@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ # Uptime berechnen@@@WCF_PRE_LINEBREAK@@@ uptime = now - boot_time@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ # Uptime in Stunden und Minuten umrechnen@@@WCF_PRE_LINEBREAK@@@ uptime_hours, remainder = divmod(uptime.total_seconds(), 3600)@@@WCF_PRE_LINEBREAK@@@ uptime_minutes = remainder // 60@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@ # Weist an das diese Funktion Stunden und Minuten ausgeben soll@@@WCF_PRE_LINEBREAK@@@ return f"{int(uptime_hours)} h , {int(uptime_minutes)} m"@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Setzt das korrekte Logo für die Distro@@@WCF_PRE_LINEBREAK@@@def get_distro_logo():@@@WCF_PRE_LINEBREAK@@@ if distro_id == "debian":@@@WCF_PRE_LINEBREAK@@@ distro_icon.configure(image=debian_logo)@@@WCF_PRE_LINEBREAK@@@ elif distro_id == "arch":@@@WCF_PRE_LINEBREAK@@@ distro_icon.configure(image=arch_logo) @@@WCF_PRE_LINEBREAK@@@ elif distro_id == "mint":@@@WCF_PRE_LINEBREAK@@@ distro_icon.configure(image=mint_logo)@@@WCF_PRE_LINEBREAK@@@ elif distro_id == "ubuntu":@@@WCF_PRE_LINEBREAK@@@ distro_icon.configure(image=ubuntu_logo)@@@WCF_PRE_LINEBREAK@@@ elif distro_id == "opensuse":@@@WCF_PRE_LINEBREAK@@@ distro_icon.configure(image=osuse_logo)@@@WCF_PRE_LINEBREAK@@@ elif distro_id == "fedora":@@@WCF_PRE_LINEBREAK@@@ distro_icon.configure(image=fedora_logo)@@@WCF_PRE_LINEBREAK@@@ else:@@@WCF_PRE_LINEBREAK@@@ distro_icon.configure(image=distro_logo)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Vars für die Labels@@@WCF_PRE_LINEBREAK@@@# Ließt den User aus@@@WCF_PRE_LINEBREAK@@@user = os.environ["USER"]@@@WCF_PRE_LINEBREAK@@@# Ließt den Host aus@@@WCF_PRE_LINEBREAK@@@hostname = socket.gethostname()@@@WCF_PRE_LINEBREAK@@@# Ließt den Pretty Name aus@@@WCF_PRE_LINEBREAK@@@os_release_pretty = distro.name(pretty=True)@@@WCF_PRE_LINEBREAK@@@# Ließt den Kernel aus@@@WCF_PRE_LINEBREAK@@@kernel_release = platform.release()@@@WCF_PRE_LINEBREAK@@@# Basis um den RAM auszulesen@@@WCF_PRE_LINEBREAK@@@svmem = psutil.virtual_memory()@@@WCF_PRE_LINEBREAK@@@# Basis um CPU-Werte auszulesen@@@WCF_PRE_LINEBREAK@@@cpu_freq = psutil.cpu_freq()@@@WCF_PRE_LINEBREAK@@@# Ließt Anzahl der CPU-Kerne aus@@@WCF_PRE_LINEBREAK@@@cpu_core_count = psutil.cpu_count(logical=False)@@@WCF_PRE_LINEBREAK@@@# Gibt die aktuelle Shell aus@@@WCF_PRE_LINEBREAK@@@active_shell = os.environ["SHELL"]@@@WCF_PRE_LINEBREAK@@@# Gibt die Distro-ID aus@@@WCF_PRE_LINEBREAK@@@distro_id = distro.id()@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Erstelle das Hauptfenster@@@WCF_PRE_LINEBREAK@@@root = tk.Tk()@@@WCF_PRE_LINEBREAK@@@root.title("Neofetch-Tk")@@@WCF_PRE_LINEBREAK@@@root.geometry("800x500")@@@WCF_PRE_LINEBREAK@@@root["background"]="#FFFFFF" # Weiß@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Distro Logos@@@WCF_PRE_LINEBREAK@@@distro_logo = tk.PhotoImage(file="images/test.png")@@@WCF_PRE_LINEBREAK@@@arch_logo = tk.PhotoImage(file="images/arch_logo_350.png")@@@WCF_PRE_LINEBREAK@@@debian_logo = tk.PhotoImage(file="images/debian_logo_350.png")@@@WCF_PRE_LINEBREAK@@@mint_logo = tk.PhotoImage(file="images/mint_logo_350.png")@@@WCF_PRE_LINEBREAK@@@suse_logo = tk.PhotoImage(file="images/osuse_logo_350.png")@@@WCF_PRE_LINEBREAK@@@ubuntu_logo = tk.PhotoImage(file="images/ubuntu_logo_350.png")@@@WCF_PRE_LINEBREAK@@@fedora_logo = tk.PhotoImage(file="images/fedora_logo_350.png")@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Einen Frame Zeichen@@@WCF_PRE_LINEBREAK@@@logo_frame = tk.Frame(root,background="#FFFFFF")@@@WCF_PRE_LINEBREAK@@@logo_frame.pack(fill="both",expand=False,side='left',padx=10,pady=10)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Distro-Logo-Label@@@WCF_PRE_LINEBREAK@@@distro_icon = tk.Label(logo_frame,text="DISTRO LOGO",image=distro_logo,background="#FFFFFF")@@@WCF_PRE_LINEBREAK@@@distro_icon.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Einen Frame Zeichen@@@WCF_PRE_LINEBREAK@@@stat_frame = tk.Frame(root,background="#FFFFFF")@@@WCF_PRE_LINEBREAK@@@stat_frame.pack(fill="both",expand=True,side='left',padx=10,pady=10)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text USER@HOST@@@WCF_PRE_LINEBREAK@@@user_host_label = tk.Label(stat_frame,text=f"{user}@{hostname}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@user_host_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text OS:@@@WCF_PRE_LINEBREAK@@@os_label = tk.Label(stat_frame,text=f"OS: {os_release_pretty}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@os_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text Host:@@@WCF_PRE_LINEBREAK@@@host_label = tk.Label(stat_frame,text=f"Host: {hostname}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@host_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text Kernel:@@@WCF_PRE_LINEBREAK@@@kernel_label = tk.Label(stat_frame,text=f"Kernel: {kernel_release}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@kernel_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text Uptime:@@@WCF_PRE_LINEBREAK@@@uptime_label = tk.Label(stat_frame,text=f"Uptime: {get_sys_uptime()}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@uptime_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text Shell:@@@WCF_PRE_LINEBREAK@@@shell_label = tk.Label(stat_frame,text=f"Shell: {active_shell}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@shell_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text Resolution:@@@WCF_PRE_LINEBREAK@@@res_label = tk.Label(stat_frame,text=f"Resolution: {get_screen_size()}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@res_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text DE:@@@WCF_PRE_LINEBREAK@@@de_label = tk.Label(stat_frame,text=f"DE: {get_desktop_environment()}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@de_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text Window-Manager@@@WCF_PRE_LINEBREAK@@@wm_label = tk.Label(stat_frame,text=f"WM: {get_window_manager_name()}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@wm_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text Theme@@@WCF_PRE_LINEBREAK@@@wm_theme_label = tk.Label(stat_frame,text=f"Theme: {get_desktop_theme()}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@wm_theme_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@icon_theme_label = tk.Label(stat_frame,text=f"Icons: {get_desktop_icons()}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@icon_theme_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text CPU:@@@WCF_PRE_LINEBREAK@@@cpu_label = tk.Label(stat_frame,text=f"CPU: ({cpu_core_count}) @ {cpu_freq.max:.2f} Mhz",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@cpu_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Label mit Text Memory:@@@WCF_PRE_LINEBREAK@@@mem_label = tk.Label(stat_frame,text=f"Memory: {(get_size(svmem.used))}/{get_size(svmem.total)}",background="#FFFFFF",font=("Sans",14))@@@WCF_PRE_LINEBREAK@@@mem_label.pack(anchor=tk.NW)@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Führt get_distro_logo aus@@@WCF_PRE_LINEBREAK@@@get_distro_logo()@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@# Starte die Hauptschleife@@@WCF_PRE_LINEBREAK@@@root.mainloop()@@@WCF_PRE_LINEBREAK@@@Zum Schluss noch ein kleiner Tipp. Logik ist in Linux allgegenwärtig. Gerade wenn man System-Tools baut, kann allein dieses Wissen Gold wert sein.
Wer sich genauer mit den Mechanismen eines Desktops auseinandersetzen will, dem empfehle ich den
dconf-editorzu installieren. Hier können alle Stellschrauben logisch aufgeschlüsselt eingesehen aber auch geändert werden. Das Tool ist aber auch mit Vorsicht zu genießen.Link zu den vorangegangenen Teilen
GNU/Linux.ch ist ein Community-Projekt. Bei uns kannst du nicht nur mitlesen, sondern auch selbst aktiv werden. Wir freuen uns, wenn du mit uns über die Artikel in unseren Chat-Gruppen oder im Fediverse diskutierst. Auch du selbst kannst Autor werden. Reiche uns deinen Artikelvorschlag über das Formular auf unserer Webseite ein.
Quelle: https://gnulinux.ch/python-tk-…-selbst-schreiben-teil-14