Home > front end >  Button doesn't show up tkinter
Button doesn't show up tkinter

Time:05-18

I have a class that represents a Window that contains a canvas, a label and is soon to contain some color-coordinated buttons.

Here is the code:

class Canvas():
    def __init__(self, width, height):
        self.root = tk.Tk()
        self.width = width
        self.height = height


        self.text_label = tk.Label(self.root, text="10",font=("Times New Roman", 20, "italic"))
        self.text_label.pack()

        self.canvas = tk.Canvas(master= self.root,width = self.width,height = self.height)
        self.canvas.pack()

        

        #======================
        self.redBtn = tk.Button(master=self.root,text="hello",command=lambda:self.changeColor("Red"))
        self.redBtn.pack()
        #======================

        self.root.mainloop()
canvas = Canvas(1980,1080)

Although I used redBtn.pack() on the button it doesn't show up. Does anyone know why?

The window:

CodePudding user response:

It worked. I can see number 10. Change this:

win = Window(1980,1080)

to

win = Canvas(1980,900)

So you can see the button on bottom.

  • Related