0

I'm trying to display a frame with a canvas inside in order I'll be able to change of frame with a button, but when the code is executed it does not even display the button, I don't know if it happens because of all is on a function, if doing what I think is even possible or if I'm missing something

from tkinter import *

window = Tk()
window.geometry("1200x700")
window.configure(bg = "#ffffff")

def btn_clicked():
    print("Button Clicked")

frame1 =Frame(window, width=1200, height=700)
frame1.grid(row=0, column=0)

def load_page():
    frame1.tkraise()
    frame1.pack_propagate(False)
    canvas = Canvas(
        frame1,
        bg = "#263ff8",
        height = 700,
        width = 1200,
        bd = 0,
        highlightthickness = 0,
        relief = "ridge")
    canvas.place(x = 0, y = 0)

    background_img = PhotoImage(file = f"background.png")
    background = canvas.create_image(
        601.0, 341.0,
        image=background_img)

    img0 = PhotoImage(file = f"img0.png")
    boton = Button(
        image = img0,
        borderwidth = 0,
        highlightthickness = 0,
        command = btn_clicked,
        relief = "flat")

    boton.place(
        x = 85, y = 71,
        width = 430,
        height = 99)

load_page()
window.resizable(False, False)
window.mainloop()

1 Answers1

0

Rephrased the entire code and including image:

To see button display. I had to reduced height and width in Canvas. Also The button had to reduced. In line 21, I changed bd = 10. You can comment in , because I don't used PhotoImage. you can debug see in image.

from tkinter import *


window = Tk()
window.geometry("1200x700")
window.configure(bg = "#ffffff")


def btn_clicked():
    print("Button Clicked")

frame1 =Frame(window, width=1200, height=700)
frame1.grid(row=0, column=0)


def load_page():
    frame1.tkraise()
    frame1.pack_propagate(False)
    canvas = Canvas(
        frame1,
        bg = "#263ff8",
        height = 100,
        width = 200,
        bd = 10,
        highlightthickness = 0,
        relief = "ridge")
    canvas.place(x = 0, y = 0)

    #background_img = PhotoImage(file = f"background.png")
    #background = canvas.create_image(
        #601.0, 341.0,
        #image=background_img)

    #img0 = PhotoImage(file = f"img0.png")
    boton = Button(frame1,
        #image = img0,
        borderwidth = 0,
        highlightthickness = 0,
        command = btn_clicked,
        relief = "flat")

    boton.place(
        x = 85, y = 71,
        width = 30,
        height =29)
    

load_page()
window.resizable(False, False)
window.mainloop()

Output result. you can see debug.

enter image description here

toyota Supra
  • 3,181
  • 4
  • 15
  • 19