ich habe ein kleines aber feines Problem. Ich wollte einem Button ein Bild zuweisen und habe dazu zum Testen folgenden Code benutzt:
Code: Alles auswählen
import Tkinter as tk
hf=tk.Tk()
mf=tk.Frame(hf)
photo=tk.PhotoImage(file="E:\\MyProggs\\ContactList\\ctl\\Images\\Add_Entry.gif")
b=tk.Button(mf, bg="black", foreground="blue", activeforeground="yellow", activebackground="black", font="Verdana")
b.config(image=photo)
b.pack()
mf.pack()
hf.mainloop()
Auszug aus dem Hauptprogramm:
Code: Alles auswählen
def dButton(mf, text='', x=0, y=0, w=100, h=20, fg=standardbuttonfg, bg=standardbuttonbg, afg=standardbuttonafg, abg='', command='', font='Arial %s' %(standardschriftgroesse), width=-1, border=1, anchor='center', focus=0, indicatoron=0, selectcolor=standardbuttonafg, image=""):
if width!=-1:
w=width
if abg=='':
abg=bg
b=tk.Button(mf, text=text, bg=bg, foreground=fg, activeforeground=afg, activebackground=abg, font=font, command=command)
b.place(x=x, y=y, width=w, height=h)
if image != "":
photo=tk.PhotoImage("Image\\"+image)
b.config(image=photo)
if focus==1:
b.focus_set()
return b
Und der entsprechende Aufruf:
Code: Alles auswählen
dButton(mf, image="Add_Entry.gif", w=300, h=40, x=0, y=0, command=lambda: Add(mf))
Jetzt die Frage: Was ist falsch?
Liebe Grüße,
ein verwirrter Python-Nutzer