I once read a book, or rather series of books, about a boy who lived with an old relative in a large country house. He was lonely, perhaps his parents had died. He had no friends and was far from anywhere he might make friends. He eventually sees children in the house, children whose portraits are on the wall and they became his playmates. I did not remember the title, but I did remember a lot of the plot so these books, once the internet happened, were easier to locate than the books I’ve mentioned previously.
The book is sadder than I recalled. As a child I didn’t remember reading that the children in the portrait had all died when they were young. I also thought that the boy in the book time-traveled, but I think he mostly played with the ghosts of the children, although he did see things happening in the past.