Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place a widget in a Canvas widget in Tkinter?

I want basically to be able to use a Canvas as a meta container for other widgets.

I want to divide my GUI into a left, center and middle section. Within each section I would like to be able to place widgets like: Checkbutton, Button, Label, etc.

How to place widgets in a Canvas widget?

like image 315
thenickname Avatar asked Sep 12 '25 11:09

thenickname


1 Answers

Your choices depend on what you're really trying to accomplish. Why is using a canvas preferable to using a frame?

You can easily add widgets to a canvas just like you do any other container, using pack or grid or place. when you do this, the items will not scroll when you scroll the canvas because they aren't actually part of the canvas.

The other choice is to create window objects on the canvas. You do this with the create_window method of the canvas. The advantage is, this window becomes part of the canvas and will scroll along with any other objects on the canvas. The downside is, your only option is absolute placement and you have to explicitly control the size of the widgets.

like image 74
Bryan Oakley Avatar answered Sep 15 '25 01:09

Bryan Oakley