写一个时间选择器 要求开始时间小于结束时间
时间: 2023-02-05 12:47:03 浏览: 52
下面是一个基本的时间选择器的代码示例,希望对你有帮助:
```python
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
def check_time():
start_time = start_time_entry.get()
end_time = end_time_entry.get()
if start_time >= end_time:
messagebox.showerror("Error", "开始时间必须小于结束时间")
else:
messagebox.showinfo("Success", "选择的时间区间合法")
root = Tk()
root.title("时间选择器")
start_time_label = ttk.Label(root, text="开始时间: ")
start_time_label.grid(row=0, column=0, padx=5, pady=5)
start_time_entry = ttk.Entry(root, width=20)
start_time_entry.grid(row=0, column=1, padx=5, pady=5)
end_time_label = ttk.Label(root, text="结束时间: ")
end_time_label.grid(row=1, column=0, padx=5, pady=5)
end_time_entry = ttk.Entry(root, width=20)
end_time_entry.grid(row=1, column=1, padx=5, pady=5)
check_button = ttk.Button(root, text="检查时间", command=check_time)
check_button.grid(row=2, column=0, columnspan=2, padx=5, pady=5)
root.mainloop()
```
这个时间选择器使用了 Python 的 Tkinter 库来创建图形界面,包含了两个文本输入框(开始时间和结束时间),和一个按钮用来检查所选的时间区间是否合法。当用户点击检查按钮时,代码会调用 `check_time` 函数来检查输入的时间。如果开始时间小于结束时间,那么会弹出一个信息
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)