Mar-23-2024, 01:11 PM
(This post was last modified: Mar-23-2024, 01:11 PM by Peter_Emp1.)
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
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() |
Gribouillis write Mar-23-2024, 12:24 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.