2017-12-23 25 views
-4

그래서 내가하려는 것은 Google 캘린더 또는 다른 캘린더 프로그램의보기처럼 캘린더 프레임을 만드는 것입니다. 그 곳에서 하루를 선택하고 그 날에해야 할 일들과 파이썬 tkinter를 사용하는 시간입니다. 현재 데이터베이스에 날짜, 시작 시간 및 종료 시간이 포함 된 이벤트가 있습니다. 파이썬 3을 사용하고 있음에 주목하십시오. 누구나 내게 그것을하는 방법에 대한 단서를 주거나 그것을하는 방법을 말하는 웹 사이트에 대한 링크를 보낼 수 있습니까? 그러나 제발, 나는 날짜 선택기를 찾고 있지 않습니다. 달력은 제게해야 할 일을 알려줍니다. 감사합니다;)파이썬 tkinter 이벤트에 대한 캘린더보기 만들기

+1

[asking] (https://stackoverflow.com/help/asking)을 참조하십시오. – Nae

+1

tkinter를 배워서 배우거나 HTML과 CSS를 익히고 파이썬 웹 프레임 워크 (플라스크 또는 장고 등)를 사용하여 웹 방식으로 만들 수 있습니다. 두 경로 모두에 대한 전체 서적뿐 아니라 웹 문서도 있습니다. – progmatico

+0

'tkinter'는'Label's 또는'Button's와 함께 사용하여 달력보기를 생성 할 수있는'grid()'레이아웃을 가지고 있습니다. – furas

답변

1

편집 : SO : How do I create a date picker in tkinter?에서 찾았습니다.

방금 ​​목록으로 이벤트를 표시해야하는 경우도

은 (그러나 다음 pack() 또는 Listbox. 만 Label/Button 필요가 있습니다 calendar를 사용 tkinter에 대한 위젯이 있습니다 그리고 이것은 당신은 어떤 튜토리얼에서 찾을 수 있습니다.)


Python 텍스트 또는 HTML

,536 아니라 캘린더를 생성 할 수있는 모듈을 가지고 calendar
import calendar 

text = calendar.TextCalendar() 

print(text.formatmonth(2017, 12)) 

결과 :

December 2017 
Mo Tu We Th Fr Sa Su 
      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 

또는 전체 년

print(text.formatyear(2017)) 

결과 :

        2017 

     January     February     March 
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su 
        1    1 2 3 4 5    1 2 3 4 5 
2 3 4 5 6 7 8  6 7 8 9 10 11 12  6 7 8 9 10 11 12 
9 10 11 12 13 14 15  13 14 15 16 17 18 19  13 14 15 16 17 18 19 
16 17 18 19 20 21 22  20 21 22 23 24 25 26  20 21 22 23 24 25 26 
23 24 25 26 27 28 29  27 28      27 28 29 30 31 
30 31 

     April      May      June 
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su 
       1 2  1 2 3 4 5 6 7    1 2 3 4 
3 4 5 6 7 8 9  8 9 10 11 12 13 14  5 6 7 8 9 10 11 
10 11 12 13 14 15 16  15 16 17 18 19 20 21  12 13 14 15 16 17 18 
17 18 19 20 21 22 23  22 23 24 25 26 27 28  19 20 21 22 23 24 25 
24 25 26 27 28 29 30  29 30 31     26 27 28 29 30 

     July      August     September 
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su 
       1 2   1 2 3 4 5 6     1 2 3 
3 4 5 6 7 8 9  7 8 9 10 11 12 13  4 5 6 7 8 9 10 
10 11 12 13 14 15 16  14 15 16 17 18 19 20  11 12 13 14 15 16 17 
17 18 19 20 21 22 23  21 22 23 24 25 26 27  18 19 20 21 22 23 24 
24 25 26 27 28 29 30  28 29 30 31    25 26 27 28 29 30 
31 

     October     November     December 
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su 
        1    1 2 3 4 5     1 2 3 
2 3 4 5 6 7 8  6 7 8 9 10 11 12  4 5 6 7 8 9 10 
9 10 11 12 13 14 15  13 14 15 16 17 18 19  11 12 13 14 15 16 17 
16 17 18 19 20 21 22  20 21 22 23 24 25 26  18 19 20 21 22 23 24 
23 24 25 26 27 28 29  27 28 29 30    25 26 27 28 29 30 31 
30 31 

또한 선택한 달의 날짜 객체를 제공 할 수

print(text.monthdatescalendar(2017, 12)) 

결과

[[datetime.date(2017, 11, 27), datetime.date(2017, 11, 28), datetime.date(2017, 11, 29), datetime.date(2017, 11, 30), datetime.date(2017, 12, 1), datetime.date(2017, 12, 2), datetime.date(2017, 12, 3)], 
[datetime.date(2017, 12, 4), datetime.date(2017, 12, 5), datetime.date(2017, 12, 6), datetime.date(2017, 12, 7), datetime.date(2017, 12, 8), datetime.date(2017, 12, 9), datetime.date(2017, 12, 10)], 
[datetime.date(2017, 12, 11), datetime.date(2017, 12, 12), datetime.date(2017, 12, 13), datetime.date(2017, 12, 14), datetime.date(2017, 12, 15), datetime.date(2017, 12, 16), datetime.date(2017, 12, 17)], 
[datetime.date(2017, 12, 18), datetime.date(2017, 12, 19), datetime.date(2017, 12, 20), datetime.date(2017, 12, 21), datetime.date(2017, 12, 22), datetime.date(2017, 12, 23), datetime.date(2017, 12, 24)], 
[datetime.date(2017, 12, 25), datetime.date(2017, 12, 26), datetime.date(2017, 12, 27), datetime.date(2017, 12, 28), datetime.date(2017, 12, 29), datetime.date(2017, 12, 30), datetime.date(2017, 12, 31)]] 

그리고이 같은 tkinter.Frame를 생성 클래스 생성 Calendar를 사용할 수 있습니다

enter image description here

# --- class --- 

import calendar 
import tkinter 

class TkinterCalendar(calendar.Calendar): 

    def formatmonth(self, master, year, month): 

     dates = self.monthdatescalendar(year, month) 

     frame = tkinter.Frame(master) 

     self.labels = [] 

     for r, week in enumerate(dates): 
      labels_row = [] 
      for c, date in enumerate(week): 
       label = tkinter.Button(frame, text=date.strftime('%Y\n%m\n%d')) 
       label.grid(row=r, column=c) 

       if date.month != month: 
        label['bg'] = '#aaa' 

       if c == 6: 
        label['fg'] = 'red' 

       labels_row.append(label) 
      self.labels.append(labels_row) 

     return frame 


# --- example how to use --- 

import tkinter as tk 

root = tk.Tk() 

tkcalendar = TkinterCalendar() 

for year, month in [(2017, 11), (2017, 12), (2018,1)]: 
    tk.Label(root, text = '{}/{}'.format(year, month)).pack() 

    frame = tkcalendar.formatmonth(root, year, month) 
    frame.pack() 

root.mainloop()          

enter image description here

그것은 여전히 ​​일정에 이벤트를 표시 할 필요를 기능을에 할당 버튼 (모든 날짜는 tkinter.Button입니다).