Seite 1 von 1

Button über ein Bild

Verfasst: Dienstag 12. Juni 2012, 13:57
von deather4
Also ich hab da mal so ne frage,
wie kann ich das anstellen,das ein button über/auf einem bild ist.
Bis jetzt sind die Buttons nur unter dem bild

Code: Alles auswählen

app_win=Tk()

bild=PhotoImage(file="wwm.gif")
hkb=Label(app_win,image=bild,)
hkb.pack()

mb2=Button(app_win,text='Verlassen',command=app_win.destroy)
mb2.pack()

mb=Button(app_win,text='Spielen',command=Frage50)
mb.pack()

app_win.geometry('600x250-500+350')
 
app_win.mainloop()
Danke für die Hilfe

Mfg deather

Re: Button über ein Bild

Verfasst: Dienstag 12. Juni 2012, 15:45
von wuf
Hi deather4

Wenn du die Buttons auf das Bild im Label platzieren möchtest:

Code: Alles auswählen

import Tkinter as tk

def frage_50():
    print 'Hi'
    
app_win=tk.Tk()
app_win.config(bg='yellow')

bild = tk.PhotoImage(file="wwm.gif")

hkb = tk.Label(app_win,image=bild)
hkb.propagate(False)
hkb.pack(expand=True)

mb = tk.Button(hkb,text='Spielen',command=frage_50)
mb.pack(side='bottom')

mb2 = tk.Button(hkb,text='Verlassen',command=app_win.destroy)
mb2.pack(side='bottom')

app_win.geometry('600x250-500+350')

app_win.mainloop()
BEMERKUNG: Normalerweise wird das Bild in ein Canvas-Widget eingebettet. Dann wird die Platzierung der Buttons anderst gehandhabt.

Gruß wuf :wink: