Sun*_*275 5 canvas tkinter python-3.x
我已经找这个很久了。在 tkinter 中获取 Canvas 的高度/宽度有这么难吗?我想做这样的事情:
c = Tk.Canvas(self, heigth=12, width=12)
c.create_oval(0, 0, self.height, self.width)
Run Code Online (Sandbox Code Playgroud)
这样我就可以用画布的宽度/高度的周长画一个圆。
为什么我找不到画布的宽度/高度等任何属性?
c.winfo_width并且c.winfo_height不起作用,因为这只会给我带来错误。
你能帮助我吗?这真的很烦人,因为即使在构造函数中也有属性height和width......
使用 winfo_reqwidth 和 winfo_reqheight:
root = tk.Tk()
c = tk.Canvas(root, height=120, width=120)
c.create_oval(0, 0, c.winfo_reqheight(), c.winfo_reqwidth())
c.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)