Images bei Tkinter mit after() abwechselnd darstellen

Fragen zu Tkinter.
Gesperrt
Duardo
User
Beiträge: 54
Registriert: Mittwoch 2. Juli 2014, 16:56

Hallo, zum einen habe ich bei diesem Programm das Problem, dass die Bilder nicht angezeigt werden und stattdessen nur ein Fehler kommt wenn sie gebraucht werden. Auch wüßte ich gerne, wie ich die beiden Bilder mit after() nacheinander zeigen könnte. Ich bin da völlig ratlos. Schonmal danke im voraus! :) Hier noch der Code:

Code: Alles auswählen

    # -*- coding: cp1252 -*-
    import sys
    from itertools import cycle
    import pygame
    import Tkinter as tk
    from Tkinter import *
    from functools import partial
    import random
     
    pygame.init()
     
    class SampleApp(tk.Tk):
        def __init__(self, *args, **kwargs):
            tk.Tk.__init__(self, *args, **kwargs)
           
            self.title("test")
            self.state('zoomed')
     
            container= tk.Frame(self)
            container.pack(side="top", fill="both", expand=True)
            container.grid_rowconfigure(0, weight=1)
            container.grid_columnconfigure(0, weight=1)
     
            self.frames={}
            for F in (fenster, mode1):
                frame= F(container, self)
                self.frames[F]=frame
                frame.grid(row=0, column=0, sticky="nsew")
     
            self.show_frame(fenster)
     
        def show_frame(self, c):
            frame=self.frames[c]
            frame.tkraise()
     
    class fenster(tk.Frame):
        def __init__(self, parent, controller):
            tk.Frame.__init__(self, parent)
     
            label=tk.Label(self, text="Das ist die Startseite")
            label.pack()
     
            button=tk.Button(self, text="Start",
                             command=lambda: controller.show_frame(mode1))
            button.pack()
     
    class mode1(tk.Frame):
        def __init__(self, parent, controller):
            tk.Frame.__init__(self, parent)
     
            label1=tk.Label(self, text=" ")
            label1.pack()
           
            def ok(label1):
                def do_a():
                    self.test1=pygame.mixer.Sound("test1.wav")
                    self.test1.play()
     
                    label2=Label(self)
                    im=PhotoImage(self, file="test.gif")
                    label2["image"]=im
                    label2.pack()
     
                    label1=Label(self)
                    im2=PhotoImage(self, file="test2.gif")
                    label1["image"]=im
                    label1.pack()
                   
                def do_b():
                    self.test2=pygame.mixer.Sound("test2.wav")
                    self.test2.play()
                   
                WORDS={"test1":do_a,
                       "test2":do_b}
                choice=random.choice(list(WORDS))
                label1['text']=choice
                WORDS[choice]()
     
            button1=tk.Button(self, text='Knopf', command=partial(ok, label1))
            button1.pack()
     
    if __name__== "__main__":
        app=SampleApp()
        app.mainloop()
     
Der Fehler:

Code: Alles auswählen

    Exception in Tkinter callback
    Traceback (most recent call last):
      File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__
        return self.func(*args)
      File "C:\Python27\tester.py", line 77, in ok
        WORDS[choice]()
      File "C:\Python27\tester.py", line 61, in do_a
        label2["image"]=im
      File "C:\Python27\lib\lib-tk\Tkinter.py", line 1269, in __setitem__
        self.configure({key: value})
      File "C:\Python27\lib\lib-tk\Tkinter.py", line 1262, in configure
        return self._configure('configure', cnf, kw)
      File "C:\Python27\lib\lib-tk\Tkinter.py", line 1253, in _configure
        self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
    TypeError: __str__ returned non-string (type instance)

EyDu
User
Beiträge: 4881
Registriert: Donnerstag 20. Juli 2006, 23:06
Wohnort: Berlin

Warum stellst du die selbe Frage noch einmal? hier wurde deine Frage doch schon beantwortet.
Das Leben ist wie ein Tennisball.
BlackJack

Und es gab dort auch noch ein paar Anmerkungen zum Quelltext die anscheinend auch nicht zur Kenntnis genommen wurden. Ich mache dann hier mal zu, bitte im anderen Thema weitermachen.
Gesperrt