-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.py
84 lines (65 loc) · 3.04 KB
/
index.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
import tkinter as tk
from tkinter import ttk
from youbikeTreeView import YoubikeTreeView
from tkinter import messagebox
from threading import Timer
import datasource
class Window(tk.Tk):
def __init__(self,**kwargs):
super().__init__(**kwargs)
#---------更新資料庫資料-----------------#
try:
datasource.updata_sqlite_data()
except Exception:
messagebox.showerror("錯誤",'網路不正常\n將關閉應用程式\n請稍後再試')
self.destroy()
#---------建立介面------------------------
#print(datasource.lastest_datetime_data())
topFrame = tk.Frame(self,relief=tk.GROOVE,borderwidth=1)
tk.Label(topFrame,text="台北市youbike及時資料",font=("arial", 20), bg="#333333", fg='#ffffff',padx=10,pady=10).pack(padx=20,pady=20)
topFrame.pack(pady=30)
#---------------------------------------
#----------建立搜尋------------------------
middleFrame = ttk.LabelFrame(self,text='')
tk.Label(middleFrame,text='站點名稱搜尋:').pack(side='left')
search_entry = tk.Entry(middleFrame)
search_entry.bind("<KeyRelease>", self.OnEntryClick)
search_entry.pack(side='left')
middleFrame.pack(fill='x',padx=20)
#----------------------------------------
#---------------建立treeView---------------
bottomFrame = tk.Frame(self)
self.youbikeTreeView = YoubikeTreeView(bottomFrame,show="headings",
columns=('sna','mday','sarea','ar','tot','sbi','bemp'),
height=20)
self.youbikeTreeView.pack(side='left')
vsb = ttk.Scrollbar(bottomFrame, orient="vertical", command=self.youbikeTreeView.yview)
vsb.pack(side='left',fill='y')
self.youbikeTreeView.configure(yscrollcommand=vsb.set)
bottomFrame.pack(pady=(0,30),padx=20)
#-------------------------------------------
def OnEntryClick(self,event):
searchEntry = event.widget
#使用者輸入的文字
input_word = searchEntry.get()
if input_word == "":
lastest_data = datasource.lastest_datetime_data()
self.youbikeTreeView.update_content(lastest_data)
else:
search_data = datasource.search_sitename(word=input_word)
self.youbikeTreeView.update_content(search_data)
def main():
def update_data(w:Window)->None:
datasource.updata_sqlite_data()
#-----------更新treeView資料---------------
lastest_data = datasource.lastest_datetime_data()
w.youbikeTreeView.update_content(lastest_data)
window.after(3*60*1000,update_data,w) #每隔3分鐘
window = Window()
window.title('台北市youbike2.0')
#window.geometry('600x300')
window.resizable(width=False,height=False)
update_data(window)
window.mainloop()
if __name__ == '__main__':
main()