-1

Is it possible to make button 3 have both the command to change to Page Two as well as to clear text from the textbox?

def __init__(self, parent, controller):
    global entry, i, T
    tk.Frame.__init__(self, parent)
    self.controller = controller

    S = tk.Scrollbar(self)
    T = tk.Text(self)
    S.pack(side=tk.RIGHT, fill=tk.Y)
    T.pack(fill=tk.Y)
    S.config(command=T.yview)
    T.config(yscrollcommand=S.set)
    T.insert(tk.END, "Available Days to take Annual Leave:\n%s\n" % DaysInWeek)

    label = tk.Label(self, text="Do you want Annual Leave?")
    label.pack()
    entry = tk.Entry(self)
    entry.pack()
    button2 = tk.Button(self, text="Go", command=self.Annualinput)
    button2.pack()
    button3 = tk.Button(self, text="Return",
                       command=lambda: controller.show_frame("PageTwo"))
    button3.pack()

The other command i want button3 to have is

def clear(self):
    T.delete('1.0', tk.END)

I took the switching pages code from Switch between two frames in tkinter

j_4321
  • 15,431
  • 3
  • 34
  • 61
shane
  • 3
  • 1

1 Answers1

1

Assign a callback function that does both those things:

def button3_callback(*args):
    T.delete('1.0', tk.END)
    controller.show_frame("PageTwo")

Make sure you define this function inside the __init__() function or T will be out of scope.

figbeam
  • 7,001
  • 2
  • 12
  • 18
  • Thank you so much, i tried this solution before but had defined it outside __init__() which was why i had problems. – shane Oct 17 '18 at 07:20