Writing my first TKInter application that was given to me by a designer. Lots of images and event actions.
TKInter is pretty slick and I like it a lot! But certain things are giving me fits, and it feels like I am missing something going on in the background, or that Windows+TKInter is finicky
As an example, if I have a basic file like app.py:
app = MyApp()
app.mainloop()
and another file controller.py
class MyApp(tk.Tk):
"""Application root window and Controller for all event handling """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
bg = Image.open("./images/my_bg.png")
bg = bg.resize((1024,600))
bg_img = ImageTk.PhotoImage(bg)
bg_label = ttk.Label(self, image=bg_img, background='black')
bg_label.place(x=0, y=0)
The image is not rendered. Even if I move it to its own function and invoke that after MyApp is instantiated, I get nothing.
Things that I store in MyApp, like StringVars, work just fine and I can update those from MyApp based on an event and it's reflected in the GUI. But I've figured out that images and the Canvas/plots will not update.
I got by with jamming all UI generation in the main file, but I need to update the plot on the fly based on user input and it's just not happening.
This also fails to render the background image:
app.py:
app = MyApp()
app.setBgImage()
app.mainloop()
controller.py
class MyApp(tk.Tk):
"""Application root window and Controller for all event handling """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def setBgImage(self):
bg = Image.open("./images/my_bg.png")
bg = bg.resize((1024,600))
bg_img = ImageTk.PhotoImage(bg)
bg_label = ttk.Label(self, image=bg_img, background='black')
bg_label.place(x=0, y=0)
Anyone with experience on what's going on behind the scenes with TKInter to tell me what's going on?
My next step is to try it on a Linux OS and see if maybe Windows+TKInter has issues.
Any suggestions are much appreciated.