I have a tkinter app that has 2 frames. The frame on the left has a bunch of buttons and the frame on the right has a text widget. I use the create_buttons function below to make the buttons. Is there a way to have the button stay sunken when clicked. Then when I click the next button that one stays sunken? I want to be able to see the last button clicked.

   def create_buttons(self):
        '''
        Loop that creates a button for each file in lterrors.txt.  The buttons uses the client/server name as its title
        text and a custom action that opens the appropriate file in the text widget.
        '''
        try:
            with open(App.logfile, 'r') as f:
                lines = f.readlines()
        except IOError:
            message = 'Cannot find %s.' % (App.logfile)
            showerror(title='Sorry', message=message)

        labels = []
        for i, line in enumerate(lines):
            filename = line.strip()
            filename = filename.replace('C:\LTShare', 'L:')
            host = os.path.dirname(filename)
            company = os.path.dirname(host)
            company = os.path.basename(company)
            host = os.path.split(host)[-1]
            host = host.split('-')[0]
            text = company + '-' + host
            labels.append((text, filename))

        labels.sort()
        for i, data in enumerate(labels):
            text, filename = data
            button = Button(self.frame1, text=text, command=lambda filename=filename: self.button_command(filename))
            button.grid(row=i, column=0, sticky='EW')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.