Jan-01-2021, 09:22 PM
Hi,
The code below brings up 2 windows, Login and IOT.
I'd like to add a background image in the Login window but, for some reasons, the image is added to the Main (parent) window.
Can someone, please, help me to find the error.
TIA
The code below brings up 2 windows, Login and IOT.
I'd like to add a background image in the Login window but, for some reasons, the image is added to the Main (parent) window.
Can someone, please, help me to find the error.
TIA
import tkinter as tk class Main: def __init__(self, master): self.master = master self.frame = tk.Frame(self.master) # login self.login = tk.Button(self.frame, text='Login', command=self.configLogin) # iot self.iot = tk.Button(self.frame, text='IOT', command=self.configIOT) self.iot.pack() self.login.pack ( ) self.frame.pack ( ) def configLogin( self ): self.login = tk.Toplevel(self.master) self.login.geometry ( "700x650+100+50" ) self.login.resizable(False,False) self.login.title ( 'Login' ) # background image self.login.bg = tk.PhotoImage ( file = "11.png" ) self.login.bg_image = tk.Label (image = self.login.bg).place \ ( x = 0 , y = 0 , relwidth = 1 , relheight = 1 ) self.app = Login(self.login) def configIOT( self ): self.iot = tk.Toplevel(self.master) self.iot.geometry ( '350x350' ) self.iot.resizable(False,False) self.iot.title ( 'IOT' ) self.app = IOT(self.iot) class Login: def __init__(self, master): self.master = master self.frame = tk.Frame(self.master) self.button1 = tk.Button(self.frame, text='Click me', command=lambda:self.DoSomething('Hello')) self.frame.pack() self.button1.pack() def DoSomething( self, val): print(val) class IOT: def __init__(self, master): self.master = master self.frame = tk.Frame(self.master) self.button1 = tk.Button(self.frame, text='Click me', command=lambda:self.printSome('Hello')) self.frame.pack() self.button1.pack() def printSome( self, val): print(val) if __name__ == "__main__": main = tk.Tk() app = Main(main) main.geometry('200x200') main.mainloop()