0

I am opening a master window. in this i am opening a Frame. In this frame there are 2 Buttons. I want to make the Button one enable the previously disabled Button 2.

import tkinter as tk
from tkinter import ttk, StringVar
from tkinter.constants import DISABLED

LARGE_FONT =('Verdana',12)

class Auswertung(tk.Tk):

    def __init__(self,*args, **kwargs):

        tk.Tk.__init__(self,*args,**kwargs)
        container = tk.Frame(self)
        container.grid(row=0, column=1, padx=10, pady=10)

        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}
        for F in (Datenwahl,):
            frame = F(container,self)

            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky='nsew')

        self.show_frame(Datenwahl)

    def show_frame(self,cont):

        frame = self.frames [cont] 
        frame.tkraise() 

    def enable_button2(self):
        self.button2["State"]= "NORMAL"


class Datenwahl(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self,parent,)


        label=tk.Label(self, text='Start Page', font=LARGE_FONT)
        label.grid(row=0, column=1, padx=10, pady=10 ,sticky= 'ew')

        button1 = tk.Button(self, text= 'Visit Page 1', 
                            command= lambda : controller.enable_button2)
        button1.grid(row=1, column=1, padx=10, pady=10)

        button2 = tk.Button(self, text= 'Visit Page 2', state=DISABLED,
                            command= lambda : controller.show_frame(PageTwo))
        button2.grid(row=2, column=1, padx=10, pady=10)


app = Auswertung()
app.mainloop()

The code should enable button2 the moment Button1 is pressed but it happens nothing.

I have tried to switch the self.Button or things like this but i cant make it work like it is intended to.

Most of the answers in the Web don't have the Class approach to tkinter and i cant adapt the solutions i found to my frame.

  • Your code throws `NameError: name 'PageOne' is not defined`... Maybe you should start with some code that works before fiddling with the buttons! Maybe you look here first: https://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter/7557028#7557028 – Reblochon Masque Oct 08 '19 at 09:35
  • I cut the code short to not throw too much of it around but forgot to cut the touple for the later Page switch. It now doesn't throw an error. – Pascal Prinz Oct 08 '19 at 11:14

0 Answers0