I am creating a new applications and i need to know how to couple a root.destroy and functionx() command to one button? I've tried to put the destroy command in functhonx() but that doesn't seem to work. Any ideas?

Also, I am wondering if it's possible to refresh the toplevel window to get rid of old Labels and display new ones. Any help will be greatly appreciated.

Thank You.

8 Years
Discussion Span
Last Post by Gribouillis

Create a frame in your top window and put your widgets on that. A frame destroy will destroy the frame and the widgets on it. Now you can create a new frame and widget set.


I've tried that but no luck. I wanna basically push a button and have the old labels disapear and the updated ones appear.


Looks like you need something simple like this:

import Tkinter as tk

def change_labels():
    label1.config(text='I need someone real bad.')
    label2.config(text='Are you real bad?')

root = tk.Tk()

label1 = tk.Label(root, text='Be alert.', width=50)
label2 = tk.Label(root, text='The world needs more lerts.', width=50)
button = tk.Button(root, text="Change Labels", command=change_labels)

# position the widgets
label1.grid(row=0, column=0, pady=5)
label2.grid(row=1, column=0, pady=5)
button.grid(row=2, column=0, pady=15)


I think the problem might be that i'm in a class. I'll see if I can restructure the class to make it work.


I am also having trouble coupling a destroy and functionx() command with one button. How do i do that


I think the question is difficult to understand. May be you should describe what you expect when the user pushes the button. Normally, with the button's command option, you can call a function or method, and you can do anything you want in this method.


Im trying to have the user quit a window and the program perform a function at the same time. I tried to put the destroy command in the fuunction but that doesn't work

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.