【发布时间】:2016-02-02 11:49:33
【问题描述】:
我正在创建一个从任何 csv 文件中获取列名的动态复选框,但是在选择选项后我无法清除窗口。
这是一个包含几个名字的列表的示例代码...
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 2 16:20:54 2016
------------------------Tkinter-------------------------
@author: Suresh
"""
import tkinter as tk
from tkinter import ttk #themed tk
win = tk.Tk()
win.title("py")
win.geometry("970x500")
win.configure()
#selection_frame = Frame(tk)
alabel = ttk.Label(win, text="Demo CheckBox",anchor='center')
alabel.grid(column=70, row=0)
alabel.configure(foreground='darkblue')
global check_box
def clearwindow():
check_box.grid_forget()
feat_names = ['Tv','Radio','Newspaper','Internet','Transport','Sports']
for i in range(len(feat_names)):
feat = tk.StringVar()
check_box = tk.Checkbutton(win, text=feat_names[i], variable=feat, state ='normal')
check_box.grid(column=30, row=i+14, sticky=tk.W)
check_box.deselect()
action = ttk.Button(win, text="Submit", command=clearwindow)
action.grid(column=4, row=30)
win.mainloop()
我想在点击提交按钮后立即获得一个清晰的窗口。
请帮忙!!
【问题讨论】:
标签: python-3.x for-loop checkbox dynamic tkinter