I spend some hours over the following problem: The picture pic1
(in class StartPage
) doesn't show with the following code (but a space of the right size is created for it). When I try outside the class with a particular tk.Tk()
object, everything works just fine...). What am I missing?
import tkinter as tk
from tkinter import ttk
LARGE_FONT= ("Verdana", 18)
class MyClass(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
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 = {}
frame = StartPage(container, self)
self.frames[StartPage] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
pic1 = tk.PhotoImage(file="Logo.gif").subsample(15)#.zoom
label_my_logo = tk.Label(self, image = pic1)
label_my_logo.pack()
label = tk.Label(self, text="Start Page", font=LARGE_FONT)
label.pack(pady=10,padx=10)
app = MyClass()
app.mainloop()