How to prevent a gap between two canvas in python
Both widgets have expand
set to True
,so they each are assigned some of the extra space. If you want only one to get the extra space, set expand
to False
for the other one. If you want them both to be given some of the extra space, be sure to set fill
to include the y direction.
I don't know how to make it work with pack. But you can do it with the grid manager. To have expandable widget with grid, you need to set two things. First, the "sticky" parameter allows the widget to fill the space inside his cell in the grid ('ew' fills horizontally, 'nsew' fills in both directions). Second, the weight parameter of the column and/or the row make it expendable if positive.
from tkinter import *class App: def __init__(self,master): master.title('Python Canvas Testing') master.minsize(width=550, height=450) settingscanvas = Canvas(master,bg="yellow") settingscanvas.grid(sticky='ew') datacanvas = Canvas(master,bd=1,bg="green") datacanvas.grid(sticky='nsew') master.grid_rowconfigure(1,weight=1) master.grid_columnconfigure(0, weight=1) for r in range(15): Label(settingscanvas, text='Label'+str(r+1)).grid() Label(datacanvas, text='Label 2').grid()## create main program windowwindow = Tk()## create window containerapp = App(window)mainloop()