image in GUI
Verfasst: Montag 8. September 2014, 12:32
Hallo zusammen,
ich versuche seit einiger Zeit ein Bild in ein GUI-Fenster einzufügen, habe allerdings noch nicht allzu viel Erfahrung mit Tkinter. Der folgende Code funktioniert wunderbar und das ganze sieht auch so aus, wie ich mir das vorgestellt hab.
Mein bisheriger Code ist allerdings als Klasse mit mehreren Methoden aufgebaut und ich bekomme es einfach nicht hin, das Bild dort einzufügen. Nach meinem Verständnis sollte der Code unten eigentlich das gleiche Fenster erzeugen, wie der Code oben:
Bestimmt übersehe ich eine Kleinigkeit, oder habe was falsch verstanden. Wäre super, wenn sich das mal jemand angucken könnte und mir einen Tipp gibt.
Vielen Dank schon mal
ich versuche seit einiger Zeit ein Bild in ein GUI-Fenster einzufügen, habe allerdings noch nicht allzu viel Erfahrung mit Tkinter. Der folgende Code funktioniert wunderbar und das ganze sieht auch so aus, wie ich mir das vorgestellt hab.
Code: Alles auswählen
from Tkinter import *
from PIL import ImageTk, Image
root = Tk()
root.geometry("600x300")
img = ImageTk.PhotoImage(Image.open("wald.jpg"))
panel = Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
labelFrame = LabelFrame(panel,text = "Wählen Sie")
labelFrame.pack(expand ="yes")
chosen = IntVar()
Radiobutton(labelFrame, text = "Option 1", variable = chosen, value = 1).pack(padx=50, pady=10)
Radiobutton(labelFrame, text = "Option 2", variable = chosen, value = 2).pack(padx=50, pady=10)
Button(labelFrame, text = "OK", width = "10").pack(padx=20, pady=10)
root.mainloop()Code: Alles auswählen
from Tkinter import *
from PIL import ImageTk, Image
class GUI(Frame):
def __init__ (self, master):
Frame.__init__(self, master)
self.pack(fill = "both", expand = "yes")
self.create_widgets()
def create_widgets(self):
img = ImageTk.PhotoImage(Image.open("wald.jpg"))
panel = Label(self, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
labelFrame = LabelFrame(panel,text = "Wählen Sie")
labelFrame.pack(expand ="yes")
chosen = IntVar()
Radiobutton(labelFrame, text = "Option 1", variable = chosen, value = 1).pack(padx=50, pady=10)
Radiobutton(labelFrame, text = "Option 1", variable = chosen, value = 2).pack(padx=50, pady=10)
Button(labelFrame, text = "OK", width = "10").pack(padx=20, pady=10)
root = Tk()
root.geometry("600x300")
app = GUI(root)
root.mainloop()Vielen Dank schon mal