-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.py
110 lines (85 loc) · 4.06 KB
/
Main.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#Author: Scott Grether, Dustin Grady
#Function: Create GUI with TKinter and set up widgets. Clock and weather that updates
#Status: Working/ Tested
import time
import calendar
from weather import WeatherClass
try:
#python3
from tkinter import *
except:
#python2
from Tkinter import *
time1 = time.localtime(time.time())
class Application(Frame):
def createTime(self):#Create Time widget
self.Time = Label(self.top_right, fg='white', background='black', font=self.labelfont)
self.Time.pack(side='right')
self.Time.config(borderwidth=0)
self.Time.config(highlightthickness=0)
def createCal(self):#Create calendar widget
self.Cal = Text(self.bottom_left,height=7,width=0,background='black', fg='white')
self.Cal.insert(INSERT, calendar.month(time1[0], time1[1]))
self.Cal.pack(side='left',fill='both',expand=True)
self.Cal.config(borderwidth=0)
self.Cal.config(highlightthickness=0)
def createImage(self):#Create weather image widget
self.imageWidget = Label(self.bottom_right, fg='white', background='black', font=self.labelfont)
self.imageWidget.pack(side="right")
self.imageWidget.config(borderwidth=0)
self.imageWidget.config(highlightthickness=0)
def createText(self):#Create weather text widget
self.textWidget = Label(self.bottom_right, fg='white', background='black', font=self.labelfont)
self.textWidget.config(bg='black', fg='white')
self.textWidget.config(borderwidth=0)#Get rid of 1px border
self.textWidget.config(highlightthickness=0)#Get rid of 1px border
self.textWidget.config(height=3, width=20)
self.textWidget.pack(expand=NO, fill=BOTH, side='right')
def __init__(self, master=None):
Frame.__init__(self, master)
self.labelfont = ('Courier', 20, 'bold')#Font for all the widgets
self.main_container = Frame(master, background='black')
self.main_container.pack(side='top',fill='both',expand=True)
master.minsize(width=1000,height=500)#Set window size
self.top_frame = Frame(self.main_container, background='black')
self.top_frame.pack(side='top',fill='x',expand=False)
self.bottom_frame = Frame(self.main_container, background='black')
self.bottom_frame.pack(side='bottom',fill='x',expand=False)
self.top_left = Frame(self.top_frame, background='black')
self.top_left.pack(side="left", fill="x", expand=True)
self.top_right = Frame(self.top_frame, background='black')
self.top_right.pack(side="right", fill="x", expand=True)
self.bottom_right = Frame(self.bottom_frame, background='black')
self.bottom_right.pack(side='right',fill='x',expand=True)
self.bottom_left = Frame(self.bottom_frame, background='black')
self.bottom_left.pack(side='left',fill='x',expand=True)
#Create all thew widgets
self.createTime()
self.createCal()
self.createImage()
self.createText()
self.top_left_label = Label(self.top_left, text="Top Left", fg='white', background='black')
self.top_left_label.pack(side="left")
#Display live time
def tick():
global time1
time2 = time.localtime(time.time())
if time2 != time1:
time1 = time2
app.Time.config(text=time.asctime(time1))
app.Time.after(1000, tick)
'''Draw weather status/icon'''
def draw_Weather():
global weatherClassObject
weatherClassObject = WeatherClass()
weatherImage = weatherClassObject.weatherImage
weatherInfo = weatherClassObject.location + '\n' + str(weatherClassObject.currentWeather) + '\n' + str(weatherClassObject.currentTemperature + 'F')#Get description of weather/ temperature
app.imageWidget.config(image = weatherImage) #update image
app.textWidget.config(text = weatherInfo) #update text
app.imageWidget.after(30000, draw_Weather)#update every x milliseconds
root = Tk()
root.title('Smart Mirror')
app = Application(root)
tick()#Initial call for clock ticking
draw_Weather()#Initial call to get draw_Weather going
root.mainloop()