還在用電腦碼代碼?out了,緊跟潮流鉛筆碼┑( ̄▽ ̄)┍

戲言

今天來隨便侃侃,順便分享一下今天內容。

今早腦子一沒啥事胡思亂想,想到了一個事情,就是做一個像紀念日一樣的東西,但是看到電腦又不想動。

~( ̄▽ ̄~)(~ ̄▽ ̄)~。

好了,不皮了,說正經的。爲此我就隨手拿起了身邊的鉛筆和一本方稿紙,想着先吧思路寫下來有興趣在弄弄,沒想到幾分鐘鬼畫符後便一發不可收拾了,瞎整了一通還情不自禁的打開了電腦,於是有了這個。。

當然這只是個空殼,完全沒有一點數據交互,就跟網上調侃的一樣,這僅僅是冰山一角。

整體預覽

 具體思路

詳細的就不說了,只是弄了個界面,啥都沒有,附上一張靈魂畫手的軟件草稿,裏面基本就是思路了

模塊代碼

整體代碼:

# #!/usr/bin/env python
# # -*- coding: utf-8 -*-
# # @Time    : 2020/02/29 12:21
# # @Author  : Cxk
# # @File    : main.py

import os
from tkinter import *
from tkinter.messagebox import *
from tkinter import filedialog
from tkinter import ttk # 導入ttk模塊,因爲下拉菜單控件在ttk中
from datetime import datetime

import threading
import webbrowser

class Addpage(object):
    def __init__(self, master=None):
        self.root = master#master: 父容器。
        self.createPage()
        self.year=''
        self.month=''
        self.day=''

    
    def createPage(self):
        def save():
            date=self.year+'-'+self.month+'-'+self.day
            date=datetime.strptime(date,"%Y-%m-%d")#將字符串改爲時間類型
            text.insert(INSERT, date)
            print(date)
#         self.author_page = Frame(self.root) 
#         self.author_page.pack()
        self.page = Toplevel(self.root)
        self.page.title('添加紀念日') 
        winWidth = 300
        winHeight = 350
        screenWidth = self.page.winfo_screenwidth()
        screenHeight = self.page.winfo_screenheight()

        x = int((screenWidth - winWidth) / 2)
        y = int((screenHeight - winHeight) / 2)
        # 設置窗口初始位置在屏幕居中
        self.page.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x-351, y))
        # 設置窗口圖標
        # root.iconbitmap("./image/icon.ico")
        # 設置窗口寬高固定
        self.page.resizable(0, 0)
        
        Label(self.page,font=("微軟雅黑", 12),text="標題").place(x=132,y=0)
        Entry(self.page,width=10,bd=5).place(x=108,y=25)
        Label(self.page,font=("微軟雅黑", 12),text="開始時間").place(x=120,y=55)
#         Entry(self.page,bd=5).pack()
    
        # 創建下拉菜單
        cmb = ttk.Combobox(self.page,width=11,foreground='blue',background='blue')
        cmb.place(x=0,y=85)
        # 設置下拉菜單中的值
        cmb['value'] = ('點擊選擇年份...', '1900', '1901', '1902', '1903', '1904', '1905', '1906', '1907', 
                        '1908', '1909', '1910', '1911', '1912', '1913', '1914', '1915', '1916', '1917',
                        '1918', '1919', '1920', '1921', '1922', '1923', '1924', '1925', '1926', '1927',
                        '1928', '1929', '1930', '1931', '1932', '1933', '1934', '1935', '1936', '1937',
                        '1938', '1939', '1940', '1941', '1942', '1943', '1944', '1945', '1946', '1947',
                        '1948', '1949', '1950', '1951', '1952', '1953', '1954', '1955', '1956', '1957',
                        '1958', '1959', '1960', '1961', '1962', '1963', '1964', '1965', '1966', '1967', 
                        '1968', '1969', '1970', '1971', '1972', '1973', '1974', '1975', '1976', '1977', 
                        '1978', '1979', '1980', '1981', '1982', '1983', '1984', '1985', '1986', '1987',
                        '1988', '1989', '1990', '1991', '1992', '1993', '1994', '1995', '1996', '1997',
                        '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', 
                        '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', 
                        '2018', '2019', '2020', '2021', '2022', '2023', '2024', '2025', '2026', '2027', 
                        '2028', '2029')
        # 設置默認值,即默認下拉框中的內容
        cmb.current(0)
        # 默認值中的內容爲索引,從0開始
        # 執行函數
        def func(event):
            self.year=cmb.get()
        cmb.bind("<<ComboboxSelected>>",func)
        
        # 創建下拉菜單
        cmb1 = ttk.Combobox(self.page,width=11,foreground='blue',background='blue')
        cmb1.place(x=100,y=85)
        # 設置下拉菜單中的值
        cmb1['value'] = ('點擊選擇月份...', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12')
        # 設置默認值,即默認下拉框中的內容
        cmb1.current(0)
        # 默認值中的內容爲索引,從0開始
        # 執行函數
        def func1(event):
            self.month=cmb1.get()
        cmb1.bind("<<ComboboxSelected>>",func1)
        
        # 創建下拉菜單
        cmb2 = ttk.Combobox(self.page,width=11,foreground='blue',background='blue')
        cmb2.place(x=200,y=85)
        # 設置下拉菜單中的值
        cmb2['value'] = ('點擊選擇日期...', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13',
                         '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31')
        # 設置默認值,即默認下拉框中的內容
        cmb2.current(0)
        # 默認值中的內容爲索引,從0開始
        # 執行函數
        def func2(event):
            self.day=cmb2.get()
        cmb2.bind("<<ComboboxSelected>>",func2)
        
        Label(self.page,font=("微軟雅黑", 12),text="內容詳情").place(x=120,y=110)
        text = Text(self.page,width=30, height=12)
        text.insert(INSERT, 'Hello...')
        text.place(x=45,y=140)
        Button(self.page,text='保存', bd =5,width=10,command=save).place(x=110,y=310)
        
    
        

class Infopage(object):
    def __init__(self, master=None):
        self.root = master#master: 父容器。
        self.createPage()

    
    def createPage(self):
        self.page = Toplevel(self.root)
        self.page.title('紀念日詳情') 
        winWidth = 400
        winHeight = 400
        screenWidth = self.page.winfo_screenwidth()
        screenHeight = self.page.winfo_screenheight()

        x = int((screenWidth - winWidth) / 2)
        y = int((screenHeight - winHeight) / 2)
        # 設置窗口初始位置在屏幕居中
        self.page.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x+401, y))
        # 設置窗口圖標
        # root.iconbitmap("./image/icon.ico")
        # 設置窗口寬高固定
        self.page.resizable(0, 0)
        
        Label(self.page,font=("微軟雅黑", 12),text="標題").pack()
        Label(self.page,font=("微軟雅黑", 12),text="開始到當前時間總計").pack()
        Label(self.page,font=("微軟雅黑", 12),text="內容詳情").pack()
        
class Rootpage(object):
    def __init__(self, master=None):
        self.root = master
        winWidth = 400
        winHeight = 400
        screenWidth = self.root.winfo_screenwidth()
        screenHeight = self.root.winfo_screenheight()

        x = int((screenWidth - winWidth) / 2)
        y = int((screenHeight - winHeight) / 2)
        # 設置窗口初始位置在屏幕居中
        self.root.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
        # 設置窗口圖標
        # root.iconbitmap("./image/icon.ico")
        # 設置窗口寬高固定
        self.root.resizable(0, 0)
        self.createPage()

    
    def createPage(self):
        def fun():
            Addpage(self.root)
        def fun2():
            Infopage(self.root)
        self.author_page = Frame(self.root) 
        self.author_page.pack()
        def open_url(event):
            webbrowser.open("https://me.csdn.net/Cxk___", new=0)
        Label(self.author_page,font=("微軟雅黑", 12),text="點擊聯繫作者@Cxk").pack()
        link=Label(self.author_page,font=("微軟雅黑", 12),fg='blue',text="CSDN博客@半盞清茶℡")
        link.pack()
        link.bind("<Button-1>", open_url)
        Button(root,text='+', bd =5,width=10,command=fun).place(x=160,y=55)
        j=0
        for i in range(0,2):
            Button(root,text="紀念日標題\n紀念日開始時間\n紀念日內容", bd =5,width=20,height=5,command=fun2).place(x=30+j,y=100)
            Button(root,text="紀念日標題\n紀念日開始時間\n紀念日內容", bd =5,width=20,height=5,command="#").place(x=30+j,y=205)
            j+=180
            
        # 創建下拉菜單
        cmb = ttk.Combobox(root,width=20,foreground='blue',background='blue')
        cmb.place(x=120,y=330)
        # 設置下拉菜單中的值
        cmb['value'] = ('點擊查看更多...','紀念1', '紀念2', '紀念3')
        # 設置默認值,即默認下拉框中的內容
        cmb.current(0)
        # 默認值中的內容爲索引,從0開始
        # 執行函數
        def func(event):
            print(cmb.get())
            Infopage(self.root)
        cmb.bind("<<ComboboxSelected>>",func)
if __name__ == "__main__":
    root = Tk() 
    root.title('紀念日') 
    Rootpage(root)
    root.mainloop() 

主界面:

class Rootpage(object):
    def __init__(self, master=None):
        self.root = master
        winWidth = 400
        winHeight = 400
        screenWidth = self.root.winfo_screenwidth()
        screenHeight = self.root.winfo_screenheight()

        x = int((screenWidth - winWidth) / 2)
        y = int((screenHeight - winHeight) / 2)
        # 設置窗口初始位置在屏幕居中
        self.root.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
        # 設置窗口圖標
        # root.iconbitmap("./image/icon.ico")
        # 設置窗口寬高固定
        self.root.resizable(0, 0)
        self.createPage()

    
    def createPage(self):
        def fun():
            Addpage(self.root)
        def fun2():
            Infopage(self.root)
        self.author_page = Frame(self.root) 
        self.author_page.pack()
        def open_url(event):
            webbrowser.open("https://me.csdn.net/Cxk___", new=0)
        Label(self.author_page,font=("微軟雅黑", 12),text="點擊聯繫作者@Cxk").pack()
        link=Label(self.author_page,font=("微軟雅黑", 12),fg='blue',text="CSDN博客@半盞清茶℡")
        link.pack()
        link.bind("<Button-1>", open_url)
        Button(root,text='+', bd =5,width=10,command=fun).place(x=160,y=55)
        j=0
        for i in range(0,2):
            Button(root,text="紀念日標題\n紀念日開始時間\n紀念日內容", bd =5,width=20,height=5,command=fun2).place(x=30+j,y=100)
            Button(root,text="紀念日標題\n紀念日開始時間\n紀念日內容", bd =5,width=20,height=5,command="#").place(x=30+j,y=205)
            j+=180
            
        # 創建下拉菜單
        cmb = ttk.Combobox(root,width=20,foreground='blue',background='blue')
        cmb.place(x=120,y=330)
        # 設置下拉菜單中的值
        cmb['value'] = ('點擊查看更多...','紀念1', '紀念2', '紀念3')
        # 設置默認值,即默認下拉框中的內容
        cmb.current(0)
        # 默認值中的內容爲索引,從0開始
        # 執行函數
        def func(event):
            print(cmb.get())
            Infopage(self.root)
        cmb.bind("<<ComboboxSelected>>",func)

紀念日詳情模塊:

class Infopage(object):
    def __init__(self, master=None):
        self.root = master#master: 父容器。
        self.createPage()

    
    def createPage(self):
        self.page = Toplevel(self.root)
        self.page.title('紀念日詳情') 
        winWidth = 400
        winHeight = 400
        screenWidth = self.page.winfo_screenwidth()
        screenHeight = self.page.winfo_screenheight()

        x = int((screenWidth - winWidth) / 2)
        y = int((screenHeight - winHeight) / 2)
        # 設置窗口初始位置在屏幕居中
        self.page.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x+401, y))
        # 設置窗口圖標
        # root.iconbitmap("./image/icon.ico")
        # 設置窗口寬高固定
        self.page.resizable(0, 0)
        
        Label(self.page,font=("微軟雅黑", 12),text="標題").pack()
        Label(self.page,font=("微軟雅黑", 12),text="開始到當前時間總計").pack()
        Label(self.page,font=("微軟雅黑", 12),text="內容詳情").pack()

紀念日添加模塊:

class Addpage(object):
    def __init__(self, master=None):
        self.root = master#master: 父容器。
        self.createPage()
        self.year=''
        self.month=''
        self.day=''

    
    def createPage(self):
        def save():
            date=self.year+'-'+self.month+'-'+self.day
            date=datetime.strptime(date,"%Y-%m-%d")#將字符串改爲時間類型
            text.insert(INSERT, date)
            print(date)
#         self.author_page = Frame(self.root) 
#         self.author_page.pack()
        self.page = Toplevel(self.root)
        self.page.title('添加紀念日') 
        winWidth = 300
        winHeight = 350
        screenWidth = self.page.winfo_screenwidth()
        screenHeight = self.page.winfo_screenheight()

        x = int((screenWidth - winWidth) / 2)
        y = int((screenHeight - winHeight) / 2)
        # 設置窗口初始位置在屏幕居中
        self.page.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x-351, y))
        # 設置窗口圖標
        # root.iconbitmap("./image/icon.ico")
        # 設置窗口寬高固定
        self.page.resizable(0, 0)
        
        Label(self.page,font=("微軟雅黑", 12),text="標題").place(x=132,y=0)
        Entry(self.page,width=10,bd=5).place(x=108,y=25)
        Label(self.page,font=("微軟雅黑", 12),text="開始時間").place(x=120,y=55)
#         Entry(self.page,bd=5).pack()
    
        # 創建下拉菜單
        cmb = ttk.Combobox(self.page,width=11,foreground='blue',background='blue')
        cmb.place(x=0,y=85)
        # 設置下拉菜單中的值
        cmb['value'] = ('點擊選擇年份...', '1900', '1901', '1902', '1903', '1904', '1905', '1906', '1907', 
                        '1908', '1909', '1910', '1911', '1912', '1913', '1914', '1915', '1916', '1917',
                        '1918', '1919', '1920', '1921', '1922', '1923', '1924', '1925', '1926', '1927',
                        '1928', '1929', '1930', '1931', '1932', '1933', '1934', '1935', '1936', '1937',
                        '1938', '1939', '1940', '1941', '1942', '1943', '1944', '1945', '1946', '1947',
                        '1948', '1949', '1950', '1951', '1952', '1953', '1954', '1955', '1956', '1957',
                        '1958', '1959', '1960', '1961', '1962', '1963', '1964', '1965', '1966', '1967', 
                        '1968', '1969', '1970', '1971', '1972', '1973', '1974', '1975', '1976', '1977', 
                        '1978', '1979', '1980', '1981', '1982', '1983', '1984', '1985', '1986', '1987',
                        '1988', '1989', '1990', '1991', '1992', '1993', '1994', '1995', '1996', '1997',
                        '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', 
                        '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', 
                        '2018', '2019', '2020', '2021', '2022', '2023', '2024', '2025', '2026', '2027', 
                        '2028', '2029')
        # 設置默認值,即默認下拉框中的內容
        cmb.current(0)
        # 默認值中的內容爲索引,從0開始
        # 執行函數
        def func(event):
            self.year=cmb.get()
        cmb.bind("<<ComboboxSelected>>",func)
        
        # 創建下拉菜單
        cmb1 = ttk.Combobox(self.page,width=11,foreground='blue',background='blue')
        cmb1.place(x=100,y=85)
        # 設置下拉菜單中的值
        cmb1['value'] = ('點擊選擇月份...', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12')
        # 設置默認值,即默認下拉框中的內容
        cmb1.current(0)
        # 默認值中的內容爲索引,從0開始
        # 執行函數
        def func1(event):
            self.month=cmb1.get()
        cmb1.bind("<<ComboboxSelected>>",func1)
        
        # 創建下拉菜單
        cmb2 = ttk.Combobox(self.page,width=11,foreground='blue',background='blue')
        cmb2.place(x=200,y=85)
        # 設置下拉菜單中的值
        cmb2['value'] = ('點擊選擇日期...', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13',
                         '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31')
        # 設置默認值,即默認下拉框中的內容
        cmb2.current(0)
        # 默認值中的內容爲索引,從0開始
        # 執行函數
        def func2(event):
            self.day=cmb2.get()
        cmb2.bind("<<ComboboxSelected>>",func2)
        
        Label(self.page,font=("微軟雅黑", 12),text="內容詳情").place(x=120,y=110)
        text = Text(self.page,width=30, height=12)
        text.insert(INSERT, 'Hello...')
        text.place(x=45,y=140)
        Button(self.page,text='保存', bd =5,width=10,command=save).place(x=110,y=310)

整體事件

  • ----進入主界面
  • ----檢查數據庫內容,並顯示最新四條數據,其餘數據用下拉框選擇,選擇標題進入詳情頁面
  • ----最上面添加紀念日
  • ----進入添加頁面
  • ----存入數據庫
  • ----點擊主頁面更新按鈕更新數據(現在還沒加上去)

遇到問題

tkinter庫沒有選擇時間控件,最後想了下采用三個下拉框選擇,並將選擇的時間變爲date類型,然後再存入數據庫中,這東西感覺挺有用的,有空完善一下看能不能做成一個通用選擇時間控件方便使用。

後期想法

  1. 完善代碼,調用雲服務器保存數據。
  2. 用戶出錯郵件發送至本人郵箱。
  3. 在詳情頁面加個 ‘歷史上的今天’ 好像還挺不錯的ㄟ(▔▽▔)ㄏ,思路有了就是懶動手,已經實現,傳送門
  4. 界面美化,當然這沒多大必要,不過那天閒的蛋疼就動手試一下。
  5. 最近在看c#,感覺python這種動態類型語言真的不適合做界面程序,等這該死的病毒過去了再去學習一下c#。
  6. 路漫漫其修遠兮,吾將上下而求索,四年一遇的29號,總該留點什麼,希望四年後回頭看這些文章會嘲諷的笑着說:”這弱智的代碼當初是怎麼寫下來的。”
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章