0

So my objective is to create a simple software that can open some websites (using the webbrowser module). I created the first window (Here the MainWin class), that displays the title (Website Access) and a big button containing an image, that leads to the second window (SecWin class). In the SecWin window, I want two buttons, one on the right, in the frame 'right', and one on the left, in the 'left' frame. In each of these button I put an image (vidim and gooim). And then, I get this thing:

The buttons are completely blank

Moreover, the buttons don't work, and the problem doesn't come from the function assigned to the buttons because they work very well if I try to replace the images in them by a text.

I'm lost because the button on the main windows works well, so I don't know where the problem comes from.

class Win:

    def __init__(self):
        self.win = Tk()
        self.win.title("Website Access")
        self.win.geometry('256x128')
        self.win.minsize = (256, 128)
        self.win.maxsize = (256, 128)
        self.win.config(bg='#D9D9D9')


class MainWin(Win):

    def __init__(self):
        super().__init__() #generates the size, color, title, ... of the window
        self.create_frame()
        self.create_main()
        self.create_title()
        self.packing()
        self.win.mainloop()

    def create_frame(self):
        self.frame = Frame(self.win, bg='#D9D9D9')

    def create_main(self):
        self.image = PhotoImage(file='Assets/Web.png').zoom(10).subsample(64)
        self.but = Button(self.frame, image=self.image, bd=5, relief=RAISED, command=Functions.main_win_button)
        self.but.pack()

    def create_title(self):
        self.title = Label(self.frame, text='Welcome to Website access', font=('Courier', 15), bg='#C9C9C9',
                           fg='#000000', bd=3, relief=SUNKEN)
        self.title.pack()

    def packing(self):
        self.frame.pack(expand=YES)


class SecWin(Win):

    def __init__(self):
        super().__init__()
        self.create_frames()
        self.create_images()
        self.create_buttons()
        self.packing()

    def create_frames(self):
        self.left = Frame(self.win, bg='#D9D9D9')
        self.right = Frame(self.win, bg='#D9D9D9')

    def create_images(self):
        self.vidim = PhotoImage(master=self.win, file='Assets/Videos.png')
        self.gooim = PhotoImage(master=self.win, file='Assets/Google.png')

    def create_buttons(self):
        self.videos = Button(self.left, image=self.vidim, bd=5, relief=RAISED,command=Functions.temp)
        self.google = Button(self.right, image=self.gooim, bd=5, relief=RAISED,command=Functions.temp)

    def packing(self):
        self.videos.pack(expand=YES)
        self.google.pack(expand=YES)
        self.right.pack(side=RIGHT)
        self.left.pack(side=LEFT)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Your example never creates an instance of `SecWin`. The problem may also be because `MainWin` and `SecWin` inherits from `Win`, giving you three root windows. Tkinter isn't designed to have three root windows. – Bryan Oakley May 01 '22 at 19:39
  • @BryanOakley, so what could I do? This is my first tkinter project so I'm not very experienced. – Primexa04 May 02 '22 at 20:21
  • You might want to read through [this answer](https://stackoverflow.com/questions/72077551/tkinter-oop-class-instance-management-with-multiple-top-level-windows/72078211#72078211) which addresses the inheritance problem. – Bryan Oakley May 02 '22 at 20:38

0 Answers0