Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否在编辑题目数据时添加自动生成input.name output.name的功能,附录一个python的小脚本 #1006

Open
duo-liang opened this issue Apr 4, 2024 · 3 comments

Comments

@duo-liang
Copy link

duo-liang commented Apr 4, 2024

自定义输入输出文件生成器.zip

import tkinter as tk
from tkinter import scrolledtext
from datetime import datetime

def generate_files():
    input_text = input_entry.get()

    # 生成input.name文件
    with open("input.name", "w") as input_file:
        input_file.write(input_text + ".in")

    # 生成output.name文件
    with open("output.name", "w") as output_file:
        output_file.write(input_text + ".out")

    # 显示生成完成的时间戳
    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    timestamp_text.config(state="normal")
    timestamp_text.delete("1.0", "end")
    timestamp_text.insert("end", "生成完成时间:" + timestamp)
    timestamp_text.config(state="disabled")

    # 显示生成的文件内容
    input_content = input_text + ".in"
    input_textbox.config(state="normal")
    input_textbox.delete("1.0", "end")
    input_textbox.insert("end", input_content)
    input_textbox.config(state="disabled")

    output_content = input_text + ".out"
    output_textbox.config(state="normal")
    output_textbox.delete("1.0", "end")
    output_textbox.insert("end", output_content)
    output_textbox.config(state="disabled")

# 创建主窗口
root = tk.Tk()
root.title("文件生成器")

# 固定窗口大小
root.geometry("630x400")
root.resizable(False, False)

# 添加输入框和标签
input_label = tk.Label(root, text="输入指定的输入输出:", font=("Arial", 12))
input_label.grid(row=0, column=0, columnspan=2,padx=10, pady=10)

input_entry = tk.Entry(root, font=("Arial", 12), justify="center")
input_entry.grid(row=1, column=0, columnspan=2,padx=10, pady=10)

# 添加生成按钮
generate_button = tk.Button(root, text="生成文件", font=("Arial", 12), command=generate_files)
generate_button.grid(row=6, column=0, columnspan=2, pady=10)

# 添加文本框显示生成完成时间
timestamp_text = scrolledtext.ScrolledText(root, width=40, height=5, font=("Arial", 12), state="disabled")
timestamp_text.grid(row=5, column=0, columnspan=2, padx=10, pady=10)

# 添加文本框显示生成的文件内容
input_textbox_label = tk.Label(root, text="input.name文件内容:", font=("Arial", 12))
input_textbox_label.grid(row=3, column=0, padx=10, pady=5)

input_textbox = scrolledtext.ScrolledText(root, width=30, height=5, font=("Arial", 12), state="disabled")
input_textbox.grid(row=4, column=0, padx=10, pady=5)

output_textbox_label = tk.Label(root, text="output.name文件内容:", font=("Arial", 12))
output_textbox_label.grid(row=3, column=1, padx=10, pady=5)

output_textbox = scrolledtext.ScrolledText(root, width=30, height=5, font=("Arial", 12), state="disabled")
output_textbox.grid(row=4, column=1, padx=10, pady=5)

# 运行主事件循环
root.mainloop()

@zhblue
Copy link
Owner

zhblue commented Apr 6, 2024

363cd78

@zhblue
Copy link
Owner

zhblue commented Apr 6, 2024

image

@duo-liang
Copy link
Author

感谢感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants