Mar-23-2024, 01:11 PM
Hello, everyone!
I'm trying to create several tk.Canvas() for each ttk.Frame() to display different figures and images on my TabWidget (ttk.Notebook).
But When i try to create two instance of tk.Canvas() on two different ttk.Frame(), NOTHING displays at all!!!
You can use any png. They don't displays!
I tried it to do smth like this:
I'm trying to create several tk.Canvas() for each ttk.Frame() to display different figures and images on my TabWidget (ttk.Notebook).
But When i try to create two instance of tk.Canvas() on two different ttk.Frame(), NOTHING displays at all!!!
You can use any png. They don't displays!
I tried it to do smth like this:
import tkinter as tk from tkinter import ttk class Guess(): def __init__(self, parent, canvas): # Creating Frame # super().__init__(parent) self.window = parent # Creating Canvas for frame Guess: # self.canvas = tk.Canvas(self.window, width=1600, height=1000) self.canvas = canvas self.canvas.pack() ###-------------------- Using canvas here....... # Add image file bg = tk.PhotoImage(file="background1.png") # Display image self.canvas.create_image(0, 0, image=bg, anchor="nw") class Full(): def __init__(self, parent, canvas): # Creating Frame # super().__init__(parent) self.window = parent # Creating Canvas for frame Full: # self.canvas = tk.Canvas(self.window, width=1600, height=1000) self.canvas = canvas self.canvas.pack() ###-------------------- Using canvas here....... # Add image file bg = tk.PhotoImage(file="background2.png") # Display image self.canvas.create_image(0, 0, image=bg, anchor="nw") class Main: def __init__(self): self.window = tk.Tk() self.window.title("Analysis") self.window.geometry('1600x1000') # create a notebook notebook = ttk.Notebook(self.window) # Create and add tabs frame_guess = ttk.Frame(notebook, width=1600, height=1000) frame_note_full = ttk.Frame(notebook, width=1600, height=1000) frame_note_shorted = ttk.Frame(notebook, width=1600, height=1000) # Create Canvas for frames frame_guess_canvas = tk.Canvas(frame_guess, width=1600, height=1000) frame_note_canvas = tk.Canvas(frame_note_full, width=1600, height=1000) # Add ttk.Frame to ttk.Notebook notebook.add(frame_guess, text="Guess") notebook.add(frame_note_full, text="Note_Full") notebook.add(frame_note_shorted, text="Note_Shorted") Guess(frame_guess, frame_guess_canvas) Full(frame_note_full, frame_note_canvas) notebook.pack(padx=5, pady=5, fill="both", expand=True) # frame_guess.pack(fill="both", expand=True) # frame_note_full.pack(fill="both", expand=True) # frame_note_shorted.pack(fill="both", expand=True) # tab1 = ttk.Frame(notebook, width=1600, height=800) # Connecting Destructor self.window.protocol('WM_DELETE_WINDOW', self.__dell__) # Add image file # bg = tk.PhotoImage(file="background.png") # Display image # self.canvas.create_image(0, 0, image=bg, anchor="nw") # Launch mainwindow self.window.mainloop() def __dell__(self): # Destroy mainwindow self.window.destroy() Main()