当前位置: 首页> 科技> 数码 > 影视广告设计制作_企业网站设计布局方式_本周新闻热点事件_网络营销推广工具有哪些

影视广告设计制作_企业网站设计布局方式_本周新闻热点事件_网络营销推广工具有哪些

时间:2025/9/3 20:08:33来源:https://blog.csdn.net/weixin_52810349/article/details/146977609 浏览次数:0次
影视广告设计制作_企业网站设计布局方式_本周新闻热点事件_网络营销推广工具有哪些

 

import tkinter as tk
import calendar
from datetime import datetimeclass DatePicker:def __init__(self):self.root = tk.Tk()self.root.withdraw()  # 隐藏主窗口self.top = tk.Toplevel(self.root)self.top.title("日期选择")self.top.geometry("320x400+500+200")self.top.resizable(False, False)self.top.configure(bg='#ffffff')self.top.option_add('*Font', 'SegoeUI')self.top.attributes('-topmost', True)self.top.overrideredirect(True)# 拖拽相关变量self.dragging = Falseself.offset_x = 0self.offset_y = 0# 颜色配置self.colors = {'primary': '#2E86C1','secondary': '#5DADE2','background': '#FFFFFF','text': '#2C3E50','highlight': '#E8F6F3','weekend': '#E74C3C','hover': '#EBF5FB'}self.current_year = datetime.now().yearself.current_month = datetime.now().monthself.today = datetime.now().dayself.selected_date = Noneself.selected_button = None# 中文月份名称self.chinese_months = ['', '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月']self.create_widgets()self.top.grab_set()  # 设置为模态窗口# 绑定拖拽事件self.top.bind("<ButtonPress-1>", self.on_drag_start)self.top.bind("<B1-Motion>", self.on_drag_motion)self.top.bind("<ButtonRelease-1>", self.on_drag_end)def create_widgets(self):self.create_header()self.create_weekdays()self.create_calendar_grid()self.create_confirm_button()def create_header(self):header_frame = tk.Frame(self.top, bg=self.colors['background'], pady=15)header_frame.pack(fill=tk.X)# 上月按钮self.btn_prev = tk.Button(header_frame,text="⟨",command=self.prev_month,font=('Segoe UI', 14, 'bold'),fg=self.colors['primary'],bg=self.colors['background'],relief='flat',activebackground=self.colors['hover'])self.btn_prev.pack(side=tk.LEFT, padx=10)# 月份显示self.month_label = tk.Label(header_frame,font=('Segoe UI', 16, 'bold'),fg=self.colors['text'],bg=self.colors['background'])self.month_label.pack(side=tk.LEFT, expand=True)# 下月按钮self.btn_next = tk.Button(header_frame,text="⟩",command=self.next_month,font=('Segoe UI', 14, 'bold'),fg=self.colors['primary'],bg=self.colors['background'],relief='flat',activebackground=self.colors['hover'])self.btn_next.pack(side=tk.RIGHT, padx=10)def create_weekdays(self):weekdays_frame = tk.Frame(self.top, bg=self.colors['background'], pady=10)weekdays_frame.pack()weekdays = ["一", "二", "三", "四", "五", "六", "日"]for i, day in enumerate(weekdays):color = self.colors['weekend'] if i >= 5 else self.colors['text']lbl = tk.Label(weekdays_frame,text=day,font=('Segoe UI', 10),fg=color,bg=self.colors['background'],width=4,padx=2)lbl.grid(row=0, column=i, sticky='ew', padx=1)for col in range(7):weekdays_frame.columnconfigure(col, weight=1, uniform='weekday')def create_calendar_grid(self):self.calendar_frame = tk.Frame(self.top, bg=self.colors['background'], padx=5, pady=5)self.calendar_frame.pack()for col in range(7):self.calendar_frame.columnconfigure(col, weight=1, uniform='day')self.update_calendar()def update_calendar(self):for widget in self.calendar_frame.winfo_children():widget.destroy()self.selected_button = Nonemonth_days = calendar.monthcalendar(self.current_year, self.current_month)month_name = self.chinese_months[self.current_month]self.month_label.config(text=f"{self.current_year} {month_name}")for week_num, week in enumerate(month_days):for day_num in range(7):day = week[day_num] if day_num < len(week) else 0if day == 0:tk.Label(self.calendar_frame, text="", bg=self.colors['background'], width=4) \.grid(row=week_num + 1, column=day_num, padx=2, pady=2)continuebtn = tk.Button(self.calendar_frame,text=str(day),width=4,relief='flat',font=('Segoe UI', 10),fg=self.colors['text'],bg=self.colors['background'],activebackground=self.colors['hover'],padx=2)def create_command(day=day, btn=btn):return lambda: self.select_date(day, btn)btn.config(command=create_command())btn.bind("<Enter>", lambda e, b=btn: b.config(bg=self.colors['hover']))btn.bind("<Leave>", lambda e, b=btn: b.config(bg=self.colors['primary'] if b == self.selected_button else self.colors['background']))if (day == self.today andself.current_month == datetime.now().month andself.current_year == datetime.now().year):btn.config(fg=self.colors['primary'], relief='groove')if day_num >= 5:btn.config(fg=self.colors['weekend'])btn.grid(row=week_num + 1, column=day_num, sticky='ew', padx=2, pady=2)def select_date(self, day, btn):if self.selected_button:self.selected_button.config(bg=self.colors['background'], fg=self.colors['text'])if (self.selected_button['text'] == str(self.today) andself.current_month == datetime.now().month):self.selected_button.config(fg=self.colors['primary'])self.selected_date = datetime(self.current_year, self.current_month, day)self.selected_button = btnself.selected_button.config(bg=self.colors['primary'], fg='white')def prev_month(self):self.current_month -= 1if self.current_month == 0:self.current_month = 12self.current_year -= 1self.update_calendar()def next_month(self):self.current_month += 1if self.current_month == 13:self.current_month = 1self.current_year += 1self.update_calendar()def create_confirm_button(self):button_frame = tk.Frame(self.top, bg=self.colors['background'], pady=15)button_frame.pack(fill=tk.X)confirm_btn = tk.Button(button_frame,text="确 定",command=self.confirm_selection,font=('Segoe UI', 12, 'bold'),fg='white',bg=self.colors['primary'],relief='flat',activebackground=self.colors['secondary'],padx=30,pady=8)confirm_btn.pack()confirm_btn.bind("<Enter>", lambda e: confirm_btn.config(bg=self.colors['secondary']))confirm_btn.bind("<Leave>", lambda e: confirm_btn.config(bg=self.colors['primary']))def confirm_selection(self):if not self.selected_date:self.selected_date = datetime.now()self.top.destroy()self.root.quit()def run(self):self.root.mainloop()return self.selected_date.strftime("%Y-%m-%d")# 拖拽相关方法def on_drag_start(self, event):self.dragging = Trueself.offset_x = event.xself.offset_y = event.ydef on_drag_motion(self, event):if self.dragging:x = self.top.winfo_x() - self.offset_x + event.xy = self.top.winfo_y() - self.offset_y + event.y# 限制窗口在屏幕内screen_width = self.top.winfo_screenwidth()screen_height = self.top.winfo_screenheight()x = max(0, min(x, screen_width - self.top.winfo_width()))y = max(0, min(y, screen_height - self.top.winfo_height()))self.top.geometry(f'+{x}+{y}')def on_drag_end(self, event):self.dragging = Falsedef get_selected_date():picker = DatePicker()return picker.run()if __name__ == "__main__":selected_date = get_selected_date()print("选择的日期是:", selected_date)

import tkinter as tk
import calendar
from datetime import datetimeclass DatePicker:def __init__(self):self.root = tk.Tk()self.root.withdraw()  # 隐藏主窗口self.top = tk.Toplevel(self.root)self.top.title("日期选择")self.top.geometry("320x400+500+200")self.top.resizable(False, False)self.top.configure(bg='#ffffff')self.top.option_add('*Font', 'SegoeUI')self.top.attributes('-topmost', True)self.top.overrideredirect(True)# 拖拽相关变量self.dragging = Falseself.offset_x = 0self.offset_y = 0# 颜色配置self.colors = {'primary': '#2E86C1','secondary': '#5DADE2','background': '#FFFFFF','text': '#2C3E50','highlight': '#E8F6F3','weekend': '#E74C3C','hover': '#EBF5FB'}self.current_year = datetime.now().yearself.current_month = datetime.now().monthself.today = datetime.now().dayself.selected_date = Noneself.selected_button = None# 中文月份名称self.chinese_months = ['', '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月']self.create_widgets()self.top.grab_set()  # 设置为模态窗口# 绑定拖拽事件self.top.bind("<ButtonPress-1>", self.on_drag_start)self.top.bind("<B1-Motion>", self.on_drag_motion)self.top.bind("<ButtonRelease-1>", self.on_drag_end)def create_widgets(self):self.create_header()self.create_weekdays()self.create_calendar_grid()self.create_confirm_button()def create_header(self):header_frame = tk.Frame(self.top, bg=self.colors['background'], pady=15)header_frame.pack(fill=tk.X)# 上月按钮self.btn_prev = tk.Button(header_frame,text="⟨",command=self.prev_month,font=('Segoe UI', 14, 'bold'),fg=self.colors['primary'],bg=self.colors['background'],relief='flat',activebackground=self.colors['hover'])self.btn_prev.pack(side=tk.LEFT, padx=10)# 月份显示self.month_label = tk.Label(header_frame,font=('Segoe UI', 16, 'bold'),fg=self.colors['text'],bg=self.colors['background'])self.month_label.pack(side=tk.LEFT, expand=True)# 下月按钮self.btn_next = tk.Button(header_frame,text="⟩",command=self.next_month,font=('Segoe UI', 14, 'bold'),fg=self.colors['primary'],bg=self.colors['background'],relief='flat',activebackground=self.colors['hover'])self.btn_next.pack(side=tk.RIGHT, padx=10)def create_weekdays(self):weekdays_frame = tk.Frame(self.top, bg=self.colors['background'], pady=10)weekdays_frame.pack()weekdays = ["一", "二", "三", "四", "五", "六", "日"]for i, day in enumerate(weekdays):color = self.colors['weekend'] if i >= 5 else self.colors['text']lbl = tk.Label(weekdays_frame,text=day,font=('Segoe UI', 10),fg=color,bg=self.colors['background'],width=4,padx=2)lbl.grid(row=0, column=i, sticky='ew', padx=1)for col in range(7):weekdays_frame.columnconfigure(col, weight=1, uniform='weekday')def create_calendar_grid(self):self.calendar_frame = tk.Frame(self.top, bg=self.colors['background'], padx=5, pady=5)self.calendar_frame.pack()for col in range(7):self.calendar_frame.columnconfigure(col, weight=1, uniform='day')self.update_calendar()def update_calendar(self):for widget in self.calendar_frame.winfo_children():widget.destroy()self.selected_button = Nonemonth_days = calendar.monthcalendar(self.current_year, self.current_month)month_name = self.chinese_months[self.current_month]self.month_label.config(text=f"{self.current_year} {month_name}")for week_num, week in enumerate(month_days):for day_num in range(7):day = week[day_num] if day_num < len(week) else 0if day == 0:tk.Label(self.calendar_frame, text="", bg=self.colors['background'], width=4) \.grid(row=week_num + 1, column=day_num, padx=2, pady=2)continuebtn = tk.Button(self.calendar_frame,text=str(day),width=4,relief='flat',font=('Segoe UI', 10),fg=self.colors['text'],bg=self.colors['background'],activebackground=self.colors['hover'],padx=2)def create_command(day=day, btn=btn):return lambda: self.select_date(day, btn)btn.config(command=create_command())btn.bind("<Enter>", lambda e, b=btn: b.config(bg=self.colors['hover']))btn.bind("<Leave>", lambda e, b=btn: b.config(bg=self.colors['primary'] if b == self.selected_button else self.colors['background']))if (day == self.today andself.current_month == datetime.now().month andself.current_year == datetime.now().year):btn.config(fg=self.colors['primary'], relief='groove')if day_num >= 5:btn.config(fg=self.colors['weekend'])btn.grid(row=week_num + 1, column=day_num, sticky='ew', padx=2, pady=2)def select_date(self, day, btn):if self.selected_button:self.selected_button.config(bg=self.colors['background'], fg=self.colors['text'])if (self.selected_button['text'] == str(self.today) andself.current_month == datetime.now().month):self.selected_button.config(fg=self.colors['primary'])self.selected_date = datetime(self.current_year, self.current_month, day)self.selected_button = btnself.selected_button.config(bg=self.colors['primary'], fg='white')def prev_month(self):self.current_month -= 1if self.current_month == 0:self.current_month = 12self.current_year -= 1self.update_calendar()def next_month(self):self.current_month += 1if self.current_month == 13:self.current_month = 1self.current_year += 1self.update_calendar()def create_confirm_button(self):button_frame = tk.Frame(self.top, bg=self.colors['background'], pady=15)button_frame.pack(fill=tk.X)confirm_btn = tk.Button(button_frame,text="确 定",command=self.confirm_selection,font=('Segoe UI', 12, 'bold'),fg='white',bg=self.colors['primary'],relief='flat',activebackground=self.colors['secondary'],padx=30,pady=8)confirm_btn.pack()confirm_btn.bind("<Enter>", lambda e: confirm_btn.config(bg=self.colors['secondary']))confirm_btn.bind("<Leave>", lambda e: confirm_btn.config(bg=self.colors['primary']))def confirm_selection(self):if not self.selected_date:self.selected_date = datetime.now()self.top.destroy()self.root.quit()def run(self):self.root.mainloop()return self.selected_date.strftime("%Y-%m-%d")# 拖拽相关方法def on_drag_start(self, event):self.dragging = Trueself.offset_x = event.xself.offset_y = event.ydef on_drag_motion(self, event):if self.dragging:x = self.top.winfo_x() - self.offset_x + event.xy = self.top.winfo_y() - self.offset_y + event.y# 限制窗口在屏幕内screen_width = self.top.winfo_screenwidth()screen_height = self.top.winfo_screenheight()x = max(0, min(x, screen_width - self.top.winfo_width()))y = max(0, min(y, screen_height - self.top.winfo_height()))self.top.geometry(f'+{x}+{y}')def on_drag_end(self, event):self.dragging = Falsedef get_selected_date():picker = DatePicker()return picker.run()if __name__ == "__main__":selected_date = get_selected_date()print("选择的日期是:", selected_date)

关键字:影视广告设计制作_企业网站设计布局方式_本周新闻热点事件_网络营销推广工具有哪些

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: