Symbol in der Titelleiste ändern ?

Fragen zu Tkinter.
Antworten
geogre
User
Beiträge: 41
Registriert: Mittwoch 20. April 2005, 13:26

hallo!

kann ich in einem Tkinter-window das kleine tk symbol in der titelleiste ändern bzw. ersetzen?

danke
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Mit etwas Suchen in Google habe ich folgendes gefunden (sind zwei Lösungen, ich habe sie zusammengelegt):

Code: Alles auswählen

import atexit
import Tkinter as tk
import win32con, win32gui

def alt1():
    root = tk.Tk()
    w = tk.Label(root, text="Hello, world!")
    w.pack()
    root.wm_iconbitmap("@x.xbm")
    root.mainloop()

def alt2():
    root = tk.Tk()
    w = tk.Label(root, text="Hello, world!")
    w.pack()
    set_icon(root, r"C:\Programme\Python\py.ico")
    root.mainloop()

def set_icon(window, icon_path):
    if not win32gui.IsWindowVisible(int(window.winfo_id())):
        window.wait_visibility(window)
    hwnd = win32gui.GetParent(int(window.winfo_id()))
    icon = win32gui.LoadImage(0, icon_path, win32con.IMAGE_ICON, 0, 0,
                              win32con.LR_DEFAULTSIZE |
                              win32con.LR_LOADFROMFILE)
    win32gui.SendMessage(hwnd, win32con.WM_SETICON,
                         win32con.ICON_BIG, icon)
    win32gui.SendMessage(hwnd, win32con.WM_SETICON,
                         win32con.ICON_SMALL, icon)
    atexit.register(destroy_icon, icon)

def destroy_icon(icon):
    win32gui.DestroyIcon(icon)

alt1()
alt2()
Wenn du grad keine XBM (X Bitmap) zur Hand hast kannst du diese nehmen:

Code: Alles auswählen

#define xlogo16_width 16
#define xlogo16_height 16
static unsigned char xlogo16_bits[] = {
    0x0f, 0x80, 0x1e, 0x80, 0x3c, 0x40, 0x78, 0x20, 0x78, 0x10,
    0xf0, 0x08, 0xe0, 0x09, 0xc0, 0x05, 0xc0, 0x02, 0x40, 0x07,
    0x20, 0x0f, 0x20, 0x1e, 0x10, 0x1e, 0x08, 0x3c, 0x04, 0x78,
    0x02, 0xf0};
Allerdings habe ich auch noch tkicon gefunden.

Viel Spass beim Aussuchen.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Flano
User
Beiträge: 43
Registriert: Sonntag 5. September 2004, 14:13

Bei mir funktioniert unter Windows:

Code: Alles auswählen

from Tkinter import *
 
root = Tk() 
root.iconbitmap('myIcon.ico') 
fr = Frame(root)  :roll: 
fr.pack() 
 
root.mainloop()
Die Datei 'myIcon.ico' muß im selben Ordner liegen. *.ico Bilderchen gibt es im Internet haufenweise zum download.
Unter Linux funktionieren bei mir leider nur die paar die Tk mitbringt z.B.
root.iconbitmap('questhead')

Edit (Leonidas): Code in Python Tags gesetzt.
Hannes-Spz

Code:
#define xlogo16_width 16
#define xlogo16_height 16
static unsigned char xlogo16_bits[] = {
0x0f, 0x80, 0x1e, 0x80, 0x3c, 0x40, 0x78, 0x20, 0x78, 0x10,
0xf0, 0x08, 0xe0, 0x09, 0xc0, 0x05, 0xc0, 0x02, 0x40, 0x07,
0x20, 0x0f, 0x20, 0x1e, 0x10, 0x1e, 0x08, 0x3c, 0x04, 0x78,
0x02, 0xf0};

?????????????????????

wie mache ich daraus nun ein ICON?
geschweige denn eine bitmap?

MfG
Hannes
ProgChild
User
Beiträge: 210
Registriert: Samstag 9. April 2005, 10:58
Kontaktdaten:

Hannes-Spz hat geschrieben:Code:
#define xlogo16_width 16
#define xlogo16_height 16
static unsigned char xlogo16_bits[] = {
0x0f, 0x80, 0x1e, 0x80, 0x3c, 0x40, 0x78, 0x20, 0x78, 0x10,
0xf0, 0x08, 0xe0, 0x09, 0xc0, 0x05, 0xc0, 0x02, 0x40, 0x07,
0x20, 0x0f, 0x20, 0x1e, 0x10, 0x1e, 0x08, 0x3c, 0x04, 0x78,
0x02, 0xf0};

?????????????????????

wie mache ich daraus nun ein ICON?
geschweige denn eine bitmap?

MfG
Hannes
Mit einem Programm. Du könntest mal danach Suchen...
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Also IrfanView kann XBMs problemlos anzeigen und auch konvertieren.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Antworten