用tkinter设置一个框,在里面输入一个数,就可以实现训练集测试集划分的比例,代码实现
时间: 2024-02-25 20:57:47 浏览: 44
好的,以下是一个简单的Tkinter界面,可以输入训练集和测试集的比例,然后点击按钮生成划分比例:
```python
import tkinter as tk
def generate_ratio():
train_ratio = float(train_entry.get())
test_ratio = float(test_entry.get())
# Calculate validation ratio
val_ratio = 1 - train_ratio - test_ratio
# Print ratios
print("Train ratio: ", train_ratio)
print("Test ratio: ", test_ratio)
print("Validation ratio: ", val_ratio)
# Create window
window = tk.Tk()
window.title("Train-Test Ratio Generator")
# Create train ratio label and entry
train_label = tk.Label(window, text="Train Ratio:")
train_label.pack()
train_entry = tk.Entry(window)
train_entry.pack()
# Create test ratio label and entry
test_label = tk.Label(window, text="Test Ratio:")
test_label.pack()
test_entry = tk.Entry(window)
test_entry.pack()
# Create generate ratio button
generate_button = tk.Button(window, text="Generate Ratio", command=generate_ratio)
generate_button.pack()
# Run window
window.mainloop()
```
你可以在train_entry和test_entry中输入要划分的比例,点击"Generate Ratio"按钮,就会输出划分比例。注意,此代码只是一个简单的例子,你需要根据自己的需求进行修改。
阅读全文