[英]Button doesn't show up tkinter
I have a class that represents a Window that contains a canvas, a label and is soon to contain some color-coordinated buttons.我有一个代表 Window 的类,它包含一个画布、一个标签,并且很快就会包含一些颜色协调的按钮。
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.尽管我在按钮上使用了
redBtn.pack()
,但它没有显示出来。 Does anyone know why?有谁知道为什么?
It worked.有效。 I can see number 10. Change this:
我可以看到 10 号。改变这个:
win = Window(1980,1080)
to至
win = Canvas(1980,900)赢=帆布(1980,900)
So you can see the button on bottom.所以你可以看到底部的按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.