Phil K. Phil K. - 1 year ago 66
Python Question

How to prevent a gap between two canvas in python

This code produces two canvases in a window. However Python does not stick them one to another but places a gap between them. This gap gets even wider when I resize the window.

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")

datacanvas = Canvas(master,bd=1,bg="green")

for r in xrange(15):
Label(settingscanvas, text='Label'+str(r+1)).grid()

Label(datacanvas, text='Label 2').grid()

## create main program window
window = Tk()

## create window container
app = App(window)


Is there any option that I miss to stick the two canvases together so that there is no gap?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download