tsounakis

Untitled

Dec 19th, 2019
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.64 KB | None | 0 0
  1. import tkinter
  2. import grcalendar
  3. import random
  4. import datetime
  5.  
  6. class App():
  7.     def __init__(self, root):
  8.         self.large_font = "Consolas 20" # άλλαξε το μορφότυπο για τα πλήκτρα
  9.         self.medium_font = "Consolas 12" # άλλαξε το μορφότυπο για το ημερολόγιο  
  10.         self.colors = self.load_colors()
  11.         root.title("Ελληνικό Ημερολόγιο")
  12.         root.wm_geometry("800x800-50+50")
  13.         self.year = int(datetime.datetime.now().year)
  14.         self.widgets()
  15.  
  16.     def widgets(self):
  17.         medium_font =   "Consolas   12"
  18.         self.f1 = tkinter.Frame(root)
  19.         color = random.randint(1, len(self.colors))
  20.         self.f1.pack()
  21.         self.entryText = tkinter.StringVar()
  22.        
  23.         button_previous = tkinter.Button(self.f1, font=self.large_font, text="  <<  ", command=self.previous_year)
  24.         button_previous.pack(side='left', expand=True)
  25.        
  26.         label = tkinter.Label(self.f1, font=self.large_font, text=" Έτος: ")
  27.         label.pack(side='left', expand=True)
  28.        
  29.         self.year_box = tkinter.Entry(self.f1, font=self.large_font, textvariable=self.entryText, width=5)
  30.         self.year_box.insert(0, self.year)
  31.         self.year_box.pack(side='left', expand=True)
  32.         self.year_box.bind("<Return>", self.this_year)
  33.        
  34.         button = tkinter.Button(self.f1, font=self.large_font, text="   ΟΚ   ")
  35.         button.pack(side='left', expand=True)
  36.         button.bind('<Button-1>', self.this_year)
  37.        
  38.         button_next = tkinter.Button(self.f1, font=self.large_font, text="   >>   ", command=self.next_year)
  39.         button_next.pack(side='left', expand=True, fill='both')
  40.  
  41.         self.f2 = tkinter.Frame(root)
  42.         self.f2.pack(expand=True, fill='both')
  43.         self.text = tkinter.Text(self.f2, font=self.medium_font)
  44.         self.scroll = tkinter.Scrollbar(self.f2, command=self.text.yview)
  45.         self.scroll.pack(side='right', fill='both')
  46.         self.text.configure(yscrollcommand=self.scroll.set)
  47.         self.text.pack(side='left', fill='both', padx=20, pady=20)
  48.         self.text.configure(background = self.colors[color])
  49.         self.show_year()
  50.  
  51.  
  52.     def load_colors(self):
  53.         self.color_list=[]
  54.         try:
  55.             file_color = open('light_colors.txt', 'r')
  56.             content = file_color.read().split('\n')
  57.             for i in content:
  58.                 self.color_list.append(i)
  59.         except: pass
  60.         finally: return self.color_list
  61.  
  62.     def previous_year(self):
  63.         self.year -= 1
  64.         self.year_box.delete('0', 'end')
  65.         self.year_box.insert(0, self.year)
  66.         color = random.randint(1, len(self.colors) - 1)
  67.         self.text.configure(background = self.colors[color])
  68.         self.show_year()
  69.  
  70.     def next_year(self):
  71.         self.year += 1
  72.         self.year_box.delete('0', 'end')
  73.         self.year_box.insert(0, self.year)
  74.         color = random.randint(1, len(self.colors) - 1)
  75.         self.text.configure(background = self.colors[color])
  76.         self.show_year()
  77.  
  78.     def this_year(self, event):
  79.         if str(self.year) != str(self.year_box.get()):
  80.             color = random.randint(1, len(self.colors) - 1)
  81.             self.text.configure(background = self.colors[color])
  82.         year = self.year_box.get()
  83.         try:
  84.             self.year = int(year)
  85.             self.show_year()
  86.         except:
  87.             pass
  88.  
  89.     def show_year(self):
  90.         self.text.delete('1.0', 'end')
  91.         bruh = grcalendar.Gr_Calendar(self.year)
  92.         self.text.insert('end', bruh)
  93.  
  94. root = tkinter.Tk()
  95. a = App(root)
  96. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment