1

I'm making a program with some buttons and three images using tkinter and the grid geometry but when I try to insert more than one canvas in the grid the program crashes while launching. I tried launching the program with the three images separately and everithing works, but when I put more than one at the same time it crashes. I Didn't find anything in the web, do you know what the problem could be?

import socket
import struct
import time


root = Tk()               
root.configure(background='CadetBlue2')
root.geometry('720x480')

root.grid_columnconfigure((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23), weight=1)
root.grid_rowconfigure((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15), weight=1)

#canvas

canvas = Canvas(root, highlightthickness=0, bg = "blue2", width=20, height=90)      
canvas.pack()
canvas.grid(row=1, column = 3,  columnspan = 18, rowspan = 3)

canvasfisica = Canvas(root, highlightthickness=0, bg = "pink", width=180, height=180)
canvasfisica.pack()
canvasfisica.grid(row=8, column = 1,  columnspan = 6, rowspan = 6)


canvasvirtual = Canvas(root, highlightthickness=0, bg = "red", width=180, height=180)      
canvasvirtual.pack()
canvasvirtual.grid(row=8, column = 17,  columnspan = 6, rowspan = 6)

#Labels

lineafisica= Label(root, text = "Línea fisica", font=("Helvetica", 14), justify = CENTER)
lineafisica.configure(background='Blue')
lineafisica.grid(row=5, column = 1,  columnspan = 10, rowspan=2)
lineavirtual= Label(root, text = "Linea virtual", font=("Helvetica", 14), justify = CENTER)
lineavirtual.configure(background='Blue')
lineavirtual.grid(row=5, column = 13,  columnspan = 10, rowspan=2)

#Buttons

btnstart = Button(root, text = 'Iniciar', bd = '2')
btnstart.configure(background='DarkOliveGreen1')
btnstart.grid(row=8, column = 7,  rowspan = 2,  columnspan = 4, sticky='nsew')
btnstart2 = Button(root, text = 'Parar', bd = '2')
btnstart2.configure(background='firebrick1')
btnstart2.grid(row=10,  column = 7,  rowspan = 2,  columnspan = 4, sticky='nsew')
btnstart5 = Button(root, text = 'Reiniciar', bd = '2')
btnstart5.grid(row=12,  column = 7,  rowspan = 2,  columnspan = 4, sticky='nsew')
btnstart5.configure(background='yellow')


btnstart3 = Button(root, text = 'Iniciar', bd = '2',)
btnstart3.grid(row=8, column = 13,  rowspan = 2,  columnspan = 4, sticky='nsew')
btnstart3.configure(background='DarkOliveGreen1')
btnstart4 = Button(root, text = 'Parar', bd = '2')
btnstart4.grid(row=10,  column = 13,  rowspan = 2,  columnspan = 4, sticky='nsew')
btnstart4.configure(background='firebrick1')
btnstart6 = Button(root, text = 'Pulsador', bd = '2')
btnstart6.grid(row=12,  column = 13,  rowspan = 2,  columnspan = 4, sticky='nsew')
btnstart6.configure(background='yellow')


root.mainloop()
urko6667
  • 13
  • 2
  • 2
    I get `_tkinter.TclError: cannot use geometry manager pack inside . which already has slaves managed by grid`. I think you can't use `pack` and `grid` together. Try to remove the lines with `pack()`. – mportes Oct 29 '19 at 13:23
  • Thanks myrmica, that was the problem. – urko6667 Oct 29 '19 at 13:29

1 Answers1

4

You can't use pack and grid together... remove the lines with "pack()" and try to run the code once again, it should work.

Please read more about pack and grid in this answer.

Kfir Ventura
  • 262
  • 2
  • 9