简单的python3 弹出窗口 选择日期的程序

import os

import tkinter as tk

from tkinter import ttk

from tkcalendar import DateEntry

from PIL import Image, ImageTk

def get_dates():

    start_date = cal_start.get()

    end_date = cal_end.get()

    print("Start Date:", start_date)

    print("End Date:", end_date)

    # 在这里添加其他需要处理的代码

root = tk.Tk()

root.title("选择日期")

root.geometry("550x150")

# # 获取当前脚本文件的绝对路径

# script_dir = os.path.dirname(os.path.abspath(__file__))

# image_path = os.path.join(script_dir, "background.jpg")

# # 打开图像文件并创建PhotoImage对象

# image = Image.open(image_path)

# photo = ImageTk.PhotoImage(image)

# # 创建Canvas对象,并将PhotoImage对象放入其中

# canvas = tk.Canvas(root, width=600, height=150)

# canvas.create_image(0, 0, image=photo, anchor="nw")

# canvas.pack()

# 创建开始日期选择器

ttk.Label(root, text="开始日期:", font=('Arial', 14)).grid(row=0, column=0)

cal_start = DateEntry(root, width=12, background='darkblue',

                      foreground='white', borderwidth=2, date_pattern='yyyy-mm-dd')

cal_start.config(font=('Arial', 14))

cal_start.place(x=150, y=50)

cal_start.grid(row=1, column=1, padx=10, pady=10)

# 创建结束日期选择器

ttk.Label(root, text="结束日期:", font=('Arial', 14)).grid(row=0, column=2)

cal_end = DateEntry(root, width=12, background='darkblue',

                    foreground='white', borderwidth=2, date_pattern='yyyy-mm-dd')

cal_end.config(font=('Arial', 14))

cal_end.place(x=370, y=50)

cal_end.grid(row=1, column=3, padx=10, pady=10)


 

# 创建按钮来获取日期

ttk.Button(root, text="获取日期", command=get_dates).place(x=200, y=100)

root.mainloop()

你可能感兴趣的:(python)