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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
import os
import CalculateStock
import tkinter.messagebox
import pandas as pd
from tkinter import *
import GetData
import CsvChangeForStockStats
class showStockStats:
def __init__(self):
self.win = Tk()
self.win.title("股票相应趋势图分析")
self.txtSeekStock = StringVar()
self.txtStartDate = StringVar()
self.txtEndDate = StringVar()
self.basepath = os.path.dirname(__file__)
def createLabel(self):
labelSeekStock = Label(self.win, text="请输入查询股票代码", font='楷体 -24 bold')
labelSeekStock.grid(row=0, column=0)
labelStartDate = Label(self.win, text="开始时间", font='楷体 -24 bold')
labelStartDate.grid(row=1, column=0)
labelEndDate = Label(self.win, text="结束时间", font='楷体 -24 bold')
labelEndDate.grid(row=1, column=2)
labelPs = Label(self.win, text='注1:时间格式如下 20220421 需严格按照本格式输入,且若是修改日期需要重新下载\n'
'注2:输入股票代码,起止时间后,需先进行数据下载,才能展现股票指标,\n '
'若使用结束后不需要该数据,可点击删除,\n否则将保留于当前文件夹下的数据文件夹中。', font='楷体 -24 bold')
labelPs.grid(row=5,columnspan=5)
def createTxt(self):
EntrySeekStock = Entry(self.win, textvariable=self.txtSeekStock, width=24, font='楷体 -24')
EntrySeekStock.grid(row=0, column=1)
EntryStartDate = Entry(self.win, textvariable=self.txtStartDate, width=24, font='楷体 -24')
EntryStartDate.grid(row=1, column=1)
EntryEndDate = Entry(self.win, textvariable=self.txtEndDate, width=24, font='楷体 -24')
EntryEndDate.grid(row=1, column=3)
def getCode(self):
return str(self.txtSeekStock.get())
def getStartDate(self):
return str(self.txtStartDate.get())
def getEndDate(self):
return str(self.txtEndDate.get())
def MACD_Show(self):
try:
code = self.txtSeekStock.get()
stockStat = CalculateStock.stockstats.StockDataFrame.retype(
pd.read_csv(self.basepath + '/' + '数据' + '/' + str(code) + '_ForStockStats.csv'))
CalculateStock.MACD(stockStat)
except:
tkinter.messagebox.showerror('错误', "数据未下载")
def BOLL_Show(self):
try:
code = self.txtSeekStock.get()
stockStat = CalculateStock.stockstats.StockDataFrame.retype(
pd.read_csv(self.basepath + '\\' + '数据' + '\\' + str(code) + '_ForStockStats.csv'))
CalculateStock.BOLL(stockStat)
except:
tkinter.messagebox.showerror('错误', "数据未下载")
def ADX_Show(self):
try:
code = self.txtSeekStock.get()
stockStat = CalculateStock.stockstats.StockDataFrame.retype(
pd.read_csv(self.basepath + '\\' + '数据' + '\\' + str(code) + '_ForStockStats.csv'))
CalculateStock.ADX(stockStat)
except:
tkinter.messagebox.showerror('错误', "数据未下载")
def RSI_Show(self):
try:
code = self.txtSeekStock.get()
stockStat = CalculateStock.stockstats.StockDataFrame.retype(
pd.read_csv(self.basepath + '\\' + '数据' + '\\' + str(code) + '_ForStockStats.csv'))
CalculateStock.RSI(stockStat)
except:
tkinter.messagebox.showerror('错误', "数据未下载")
def CCI_Show(self):
try:
code = self.txtSeekStock.get()
stockStat = CalculateStock.stockstats.StockDataFrame.retype(
pd.read_csv(self.basepath + '\\' + '数据' + '\\' + str(code) + '_ForStockStats.csv'))
CalculateStock.CCI(stockStat)
except:
tkinter.messagebox.showerror('错误', "数据未下载")
def MA_Show(self):
try:
code = self.txtSeekStock.get()
stockStat = CalculateStock.stockstats.StockDataFrame.retype(
pd.read_csv(self.basepath + '\\' + '数据' + '\\' + str(code) + '_ForStockStats.csv'))
CalculateStock.MA(stockStat)
except:
tkinter.messagebox.showerror('错误', "数据未下载")
def DownloadData(self):
try:
if str(self.getCode()) == "":
tkinter.messagebox.showerror('错误', '股票代码不能为空')
elif str(self.getStartDate()) == "":
tkinter.messagebox.showerror('错误', '开始时间不能为空')
elif str(self.getEndDate()) == '':
tkinter.messagebox.showerror('错误', '结束时间不能为空')
else:
Download = GetData.Download_HistoryStock(str(self.getCode()), self.getStartDate(), self.getEndDate())
Download.Download()
tkinter.messagebox.showinfo("成功", '下载完成,保存在当前文件夹中的数据文件夹中')
CsvChangeForStockStats.CsvChangeToStockStats(str(self.getCode()))
except:
tkinter.messagebox.showerror('错误', "股票代码输入错误,或未按要求输入时间(若确认正常,可能是由于网站维护造成爬取失败)")
def DeleteData(self):
try:
os.remove(self.basepath + "\\" + "数据" + "\\" + str(self.getCode()) + ".csv")
os.remove(self.basepath + "\\" + "数据" + "\\" + str(self.getCode()) + "_ForStockStats.csv")
tkinter.messagebox.showinfo("成功", '删除成功')
except:
tkinter.messagebox.showerror('错误', '文件已删除或不存在')
def createButtom(self):
btnMACD = Button(self.win, text='显示MACD线', command=self.MACD_Show, font='楷体 -24',
width=12)
btnMACD.grid(row=3, column=0, sticky=W)
btnBOLL = Button(self.win, text='显示BOLL线', command=self.BOLL_Show, font='楷体 -24',
width=12)
btnBOLL.grid(row=3, column=2, sticky=W)
btnADX = Button(self.win, text='显示ADX线', command=self.ADX_Show, font='楷体 -24',
width=12)
btnADX.grid(row=3, column=4, sticky=W)
btnRSI = Button(self.win, text='显示RSI线', command=self.RSI_Show, font='楷体 -24',
width=12)
btnRSI.grid(row=4, column=0, sticky=W)
btnCCI = Button(self.win, text='显示CCI线', command=self.CCI_Show, font='楷体 -24',
width=12)
btnCCI.grid(row=4, column=2, sticky=W)
btnMA = Button(self.win, text='显示MA线', command=self.MA_Show, font='楷体 -24',
width=12)
btnMA.grid(row=4, column=4, sticky=W)
btnClose = Button(self.win, text='关闭窗口', command=self.win.quit, font='楷体 -24', width=12)
btnClose.grid(row=2, column=4, sticky=W)
btnDownload = Button(self.win, text='下载数据', command=self.DownloadData, font='楷体 -24',
width=12)
btnDownload.grid(row=2, column=0, sticky=W)
btnDownload = Button(self.win, text='删除数据', command=self.DeleteData, font='楷体 -24',
width=12)
btnDownload.grid(row=2, column=2, sticky=W)
def run(self):
self.createLabel()
self.createTxt()
self.createButtom()
self.win.mainloop()
|