Configure label from different class - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Configure label from different class (/thread-20537.html) |
Configure label from different class - storzo - Aug-16-2019 Hi I stack, i can't change image in config via main class: class SETUP: def __init__(self, root): self.root = root self.frame = Frame(self.root) #button for open new window help self.button = Button(self.root, command=self.help) self.button.place(x=0, y=0) #button for change image for help self.button = Button(self.root, command=self.change_backgound_class_hhelp) self.button.place(x=100, y=0) def change_backgound_class_hhelp(self): #<<<<<<<here is problem! self.hhelp.config(root, image=help2_bg) # def for new window create def help(self): self.newWindow2 = Toplevel(self.root) bb = hhelp(self.newWindow2) class hhelp(): def __init__(self, root): self.root = root self.frame2 = Frame(self.root) self.frame2.pack() self.bgg = Label(self.root,image=help1_bg).place(x=0, y=0, relwidth=1, relheight=1) if __name__ == '__main__': root = Tk() help1_bg = ImageTk.PhotoImage(Image.open("help.jpg")) help2_bg = ImageTk.PhotoImage(Image.open("help1.jpg")) root.overrideredirect(0) b = SETUP(root) root.mainloop() RE: Configure label from different class - Denni - Aug-19-2019 Okay several things wrong from what I can see
encounter errors because someone presses the 2nd button first -- I would definitely state that you need to name your 2 buttons something different like self.btnOpen1 and self.btnOpen2 but it would be even better to name them more appropriately based on what they do. If you trying to have the button do two different things then you would have the button call a function that then called whatever functionality you wanted it to perform self.btnOpen = Button(self.root, command=self.DoOneOfThese) def DoOneOfThese() if self.YourCriterion: self.help() else: self.change_background_class_hhelp() |