search_button = tk.Button(window, text='搜索', command=on_search)
result_text = tk.Text(window, height=20)
该回答引用chatgpt:
import tkinter as tk
import calendar
def display_calendar(year, month):
cal = calendar.month(year, month)
result_text.delete("1.0", tk.END) # 清空文本框内容
result_text.insert(tk.END, cal)
def on_search():
year = int(year_entry.get())
month = int(month_entry.get())
display_calendar(year, month)
window = tk.Tk()
# 创建年份输入框和标签
year_label = tk.Label(window, text="年份:")
year_label.pack()
year_entry = tk.Entry(window)
year_entry.pack()
# 创建月份输入框和标签
month_label = tk.Label(window, text="月份:")
month_label.pack()
month_entry = tk.Entry(window)
month_entry.pack()
# 创建搜索按钮
search_button = tk.Button(window, text='搜索', command=on_search)
search_button.pack()
# 创建结果文本框
result_text = tk.Text(window, height=20)
result_text.pack()
window.mainloop()
试下
import tkinter as tk
import calendar
# 用于在文本框中显示搜索结果
def on_search():
year = int(year_input.get())
calendar.setfirstweekday(calendar.SUNDAY)
cal = calendar.calendar(year)
result_text.delete(1.0, tk.END) # 清空文本框
result_text.insert(tk.END, cal)
# 创建主窗口
window = tk.Tk()
window.title('日历查询')
window.geometry('400x400')
# 创建标签(说明文字)
year_label = tk.Label(window, text="请输入年份:", font=('Arial', 12))
year_label.grid(row=0, column=0)
# 创建输入框
year_input = tk.Entry(window)
year_input.grid(row=0, column=1)
# 创建搜索按钮
search_button = tk.Button(window, text='搜索', command=on_search)
search_button.grid(row=0, column=2)
# 创建文本框
result_text = tk.Text(window, height=20)
result_text.grid(row=1, columnspan=3)
# 启动主循环
window.mainloop()
文本特征提取
词袋法:
主要有两个api来实现CounterVectorizer
和TfidfVectorizer
CountVectorizer:
TfidfVectorizer: