import tkinter as tk
from tkinter import messagebox as mBox
import os
def GetItems():
# ‘get the new items from folder’
name = []
for root, dirs, files in os.walk(r’C:\Users\Public\SourceFile’):
for i in files:
if ‘.xlsx’ + ’ ’ in i + ’ ': # 这里后面不加一个字母可能会出问题,加上一个(不一定是空格)可以解决99.99%的情况
name.append(i)
if ‘.xls’ + ’ ’ in i + ’ ': # 这里后面不加一个字母可能会出问题,加上一个(不一定是空格)可以解决99.99%的情况
name.append(i)
return name
def submit():
# print(1)
# print(args)
result = [var.get() for var in vars if var.get()]
print(result)
def show_items():
hobby_list = GetItems()
print(hobby_list)
for i in range(len(hobby_list)):
rollnum = hobby_list[i]
if rollnum not in re_list:
var = tk.StringVar(value=rollnum)
cb = tk.Checkbutton(text, text=rollnum, variable=var, onvalue=rollnum, offvalue='', bg='white',command='')
text.window_create('end', window=cb)
text.insert('end', '\n')
vars.append(var)
re_list.append(rollnum)
print('aaaaa')
if name == ‘main’:
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
text = tk.Text(frame, width=40, height=20)
text.pack(side=tk.LEFT, fill=tk.BOTH)
vsb = tk.Scrollbar(frame, orient=tk.VERTICAL, command=text.yview)
vsb.pack(side=tk.RIGHT, fill=tk.Y)
text.config(yscrollcommand=vsb.set)
vars = []
re_list = []
create button : GetItems/ show_items/ submit
hi_there = tk.Button(frame, text="GetItems", fg="blue", command=GetItems)
hi_there.pack(side=tk.LEFT)
show_items = tk.Button(frame, text="show_items", fg="blue", command=show_items)
show_items.pack(side=tk.LEFT)
tk.Button(root, text='Submit', command=submit).pack(side=tk.LEFT)
root.mainloop()