Apr-28-2020, 12:23 PM
I think I know why the button images don't appear. Just yesterday someone was tryin to use image buttons. Their code worked until they created a class for their window. The class/no class code was identical except for one thing; Scope.
The problem was that the images used for the buttons were local variables inside the __init__ method. An image button must not have a reference to the image because as soon as the __init__ method exited and the local image variable went poof, so did the image. Changing the image variables from local to instance variables fixed the problem.
Please don't ask me why that happened because I haven't figured it all out for myself. Using that same logic your images should not have appeared in your earlier code (the one with image buttons that didn't scroll) since your image variables were local to your win1 function. Still a bit of a mystery
Try using self.photo1 instead of photo1 and see if that makes a difference. If so, that is another piece of the puzzle and it may be worth investigating what combinations of classes/functions/globals work with image buttons.
The problem was that the images used for the buttons were local variables inside the __init__ method. An image button must not have a reference to the image because as soon as the __init__ method exited and the local image variable went poof, so did the image. Changing the image variables from local to instance variables fixed the problem.
Please don't ask me why that happened because I haven't figured it all out for myself. Using that same logic your images should not have appeared in your earlier code (the one with image buttons that didn't scroll) since your image variables were local to your win1 function. Still a bit of a mystery
Try using self.photo1 instead of photo1 and see if that makes a difference. If so, that is another piece of the puzzle and it may be worth investigating what combinations of classes/functions/globals work with image buttons.