Anfängerfrage zu Bildern mit Tk

Fragen zu Tkinter.
Antworten
sirroseide
User
Beiträge: 14
Registriert: Montag 31. Januar 2005, 15:44
Wohnort: Berlin

Wie kann man Bilder(Bitmaps) in Tk öffnen/benutzen?
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Klar geht das!
Schau mal das Intro an, das erklärt einiges.
Vielleicht bist du auch an der Interaktion PIL <-> Tkinter interessiert.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
mawe
Python-Forum Veteran
Beiträge: 1209
Registriert: Montag 29. September 2003, 17:18
Wohnort: Purkersdorf (bei Wien [Austria])

Hi!

Lustigerweise (naja, so lustig is das gar nicht :wink:) funktionieren Bitmaps bei mir nicht. Es haben auch schon andere in diesem Forum damit Probleme gehabt. In der Doku steht X11 Bitmaps. Gibt's da auch andere? Was erzeugt denn z.B. Gimp?

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

Gimp erzeugt einiges, das darfst du im Speichern Dialog auswählen..

Das eine X11 Bitmap (XBM):

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};
Das ist dagegen eine X11 Pixmap (XPM):

Code: Alles auswählen

/* XPM */

static const char * gtk_xpm{} = {
 "32 39 5 1",
 ".      c none",
 "+      c black",
 "@      c #3070E0",
 "#      c #F05050",
 "$      c #35E035",
 "................+...............",
 "..............+++++.............",
 "............+++++@@++...........",
 "..........+++++@@@@@@++.........",
 "........++++@@@@@@@@@@++........",
 "......++++@@++++++++@@@++.......",
 ".....+++@@@+++++++++++@@@++.....",
 "...+++@@@@+++@@@@@@++++@@@@+....",
 "..+++@@@@+++@@@@@@@@+++@@@@@++..",
 ".++@@@@@@+++@@@@@@@@@@@@@@@@@@++",
 ".+#+@@@@@@++@@@@+++@@@@@@@@@@@@+",
 ".+##++@@@@+++@@@+++++@@@@@@@@$@.",
 ".+###++@@@@+++@@@+++@@@@@++$$$@.",
 ".+####+++@@@+++++++@@@@@+@$$$$@.",
 ".+#####+++@@@@+++@@@@++@$$$$$$+.",
 ".+######++++@@@@@@@++@$$$$$$$$+.",
 ".+#######+##+@@@@+++$$$$$$@@$$+.",
 ".+###+++##+##+@@++@$$$$$$++$$$+.",
 ".+###++++##+##+@@$$$$$$$@+@$$@+.",
 ".+###++++++#+++@$$@+@$$@++$$$@+.",
 ".+####+++++++#++$$@+@$$++$$$$+..",
 ".++####++++++#++$$@+@$++@$$$$+..",
 ".+#####+++++##++$$++@+++$$$$$+..",
 ".++####+++##+#++$$+++++@$$$$$+..",
 ".++####+++####++$$++++++@$$$@+..",
 ".+#####++#####++$$+++@++++@$@+..",
 ".+#####++#####++$$++@$$@+++$@@..",
 ".++####++#####++$$++$$$$$+@$@++.",
 ".++####++#####++$$++$$$$$$$$+++.",
 ".+++####+#####++$$++$$$$$$$@+++.",
 "..+++#########+@$$+@$$$$$$+++...",
 "...+++########+@$$$$$$$$@+++....",
 ".....+++######+@$$$$$$$+++......",
 "......+++#####+@$$$$$@++........",
 ".......+++####+@$$$$+++.........",
 ".........++###+$$$@++...........",
 "..........++##+$@+++............",
 "...........+++++++..............",
 ".............++++..............."
 }; 
^^ Was das wohl ist? :o Ich find XPM einfach nur cool.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
mawe
Python-Forum Veteran
Beiträge: 1209
Registriert: Montag 29. September 2003, 17:18
Wohnort: Purkersdorf (bei Wien [Austria])

Hi Leonidas!

Danke! Bei Bitmap hab ich eigentlich immer an die Dinger mit der Endung bmp gedacht :wink:
Leonidas hat geschrieben: Ich find XPM einfach nur cool.
Find ich auch. Hab's mit Perl/Tk oft genutzt. Schade dass es mit Tkinter nicht geht (oder geht's doch?).

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

mawe hat geschrieben:Danke! Bei Bitmap hab ich eigentlich immer an die Dinger mit der Endung bmp gedacht :wink:
Das sind die bösen, fetten, binären, OS/2-Win Bitmaps. :twisted:
mawe hat geschrieben:
Leonidas hat geschrieben:Ich find XPM einfach nur cool.
Find ich auch. Hab's mit Perl/Tk oft genutzt. Schade dass es mit Tkinter nicht geht (oder geht's doch?).
Also PIL liest XPM und PIL und Tkinter sind gute Freunde.

Aber auch im Python Source Tarball sind unter Demos/Tix ein paar Python Scripte, die glaube ich mit XPMs arbeiten können. Du solltest mal im Demo/Tix/samples/CmpImg.py gucken, das nutzt soweit ich das sehe XPM. Das geht verwunderlicherweise sogar unter Windows.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
sirroseide
User
Beiträge: 14
Registriert: Montag 31. Januar 2005, 15:44
Wohnort: Berlin

ich meinte Bilder, die ich in Paint gemacht habe.
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Na das steht doch sicher in jeder Tk Doku.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
mawe
Python-Forum Veteran
Beiträge: 1209
Registriert: Montag 29. September 2003, 17:18
Wohnort: Purkersdorf (bei Wien [Austria])

Hi!

Na wo die Bilder herkommen ist ja wohl ziemlich egal, oder? :wink:
Wie speicherst Du die denn ab (welches Format, bmp, gif, ...)?

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

mawe hat geschrieben:Na wo die Bilder herkommen ist ja wohl ziemlich egal, oder? :wink:
Wie speicherst Du die denn ab (welches Format, bmp, gif, ...)?
Also MS Paint konnte lange Zeit nur BMP speichern inzwischen auch GIF, JPEG, TIFF und PNG, aber ich glaube sierroseide ging es um normale BMPs.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
mawe
Python-Forum Veteran
Beiträge: 1209
Registriert: Montag 29. September 2003, 17:18
Wohnort: Purkersdorf (bei Wien [Austria])

Hi!

Dann muss man wohl auf PIL zurückgreifen:

Code: Alles auswählen

from Tkinter import *
from PIL import Image, ImageTk

root = Tk()
image = Image.open("homer.bmp")
photo = ImageTk.PhotoImage(image)
label = Label(image=photo)
label.pack()
root.mainloop()
Gruß, mawe
sirroseide
User
Beiträge: 14
Registriert: Montag 31. Januar 2005, 15:44
Wohnort: Berlin

Danke mave! Endlich eine genaue Antwort auf meine ungenaue Frage. :D
sirroseide
User
Beiträge: 14
Registriert: Montag 31. Januar 2005, 15:44
Wohnort: Berlin

:? Ich habe den Programmtext von mave kopiert und in der Schule ausprobiert. Es hat geklappt. Aber zu Hause gehts nicht, weil es einen Fehler gibt: Module PIL does not exist. Ich habe die Pythonversion 2.3.4! Warum klappts nicht?
mawe
Python-Forum Veteran
Beiträge: 1209
Registriert: Montag 29. September 2003, 17:18
Wohnort: Purkersdorf (bei Wien [Austria])

Hi!

Du musst auch PIL installiert haben :wink:

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

Was ist eingentlich um PIL 1.1.5 los? Das wird ja nie released.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
mawe
Python-Forum Veteran
Beiträge: 1209
Registriert: Montag 29. September 2003, 17:18
Wohnort: Purkersdorf (bei Wien [Austria])

Hi Leonidas!

Die beta-Version gibt's schon, schau mal hier.

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

Und was spricht dagegen, dass als final zu releasen? Scheint doch ganz ok zu sein.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
mawe
Python-Forum Veteran
Beiträge: 1209
Registriert: Montag 29. September 2003, 17:18
Wohnort: Purkersdorf (bei Wien [Austria])

Jo wos was I :)
Antworten