如何在运行某个程序后立即破坏帧

时间:2016-09-25 01:39:08

标签: python tkinter

此代码用于显示2个按钮,这两个按钮都链接到启动其他代码段的定义,然后关闭窗口。我需要能够在单击按钮后关闭窗口小部件

from tkinter import *
import tkinter
import sys

root = tkinter.Tk()

def cs_age():
    print("to be completed")

def cs_male():
    print('type code here to add strength and athleticism to attributes')
    #I need code here to destroy the window that popped up
    cs_age()

def cs_female():
    print('type code here')
    # I need code here to destroy the window that popped up
    cs_age()

def close_window()
    #put code here to universally close all popped up widgets

这是显示按钮

的全部内容
frame = Frame(root)
frame.pack()

bottomframe = Frame(root)
bottomframe.pack (side = BOTTOM)

cs_gendermale_button = tkinter.Button(frame, text=("Male"), fg='blue',  command = cs_male)
cs_gendermale_button.pack( side = LEFT )

cs_genderfemale_button = tkinter.Button(frame, text=("Female"), fg='red', command = cs_female)
cs_genderfemale_button.pack( side = LEFT )

root.mainloop()

1 个答案:

答案 0 :(得分:-1)

这真的应该是评论而不是答案,但我还没有足够的声誉。 这是你正在寻找的吗? Function to close the window in Tkinter