質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -23,3 +23,363 @@
|
|
23
23
|
上記のように,同じ1でも増加によるものと減少によるものとでイベントを起こせるかを知りたいです。
|
24
24
|
|
25
25
|
また,そのようなオプションがない場合は同様の動作がどのようにできるか知りたいです。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
※以下は実際に使用しているコードです。
|
30
|
+
|
31
|
+
```ここに言語を入力
|
32
|
+
|
33
|
+
# -*- coding: utf-8 -*-
|
34
|
+
|
35
|
+
import tkinter
|
36
|
+
|
37
|
+
import openpyxl
|
38
|
+
|
39
|
+
from tkinter import ttk
|
40
|
+
|
41
|
+
from tkinter import *
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
try:
|
46
|
+
|
47
|
+
import tkinter as tk
|
48
|
+
|
49
|
+
except:
|
50
|
+
|
51
|
+
import tkinter as tk
|
52
|
+
|
53
|
+
import tkinter.scrolledtext as st
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# ウィンドウの作成
|
58
|
+
|
59
|
+
window = tkinter.Tk()
|
60
|
+
|
61
|
+
window.geometry("1358x750")
|
62
|
+
|
63
|
+
window.title("Screen Transition")
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
# 遷移前の画面の作成(画面1)
|
68
|
+
|
69
|
+
canvas1 = tkinter.Canvas(bd=0, width=1366, height=768)
|
70
|
+
|
71
|
+
canvas1.place(x=0, y=0) # キャンバス
|
72
|
+
|
73
|
+
titleLabel1 = tk.Label(canvas1, text=" ※@で画面を閉じる ", font=('Helvetica', '13'), fg='gray8')
|
74
|
+
|
75
|
+
titleLabel1.place(relx=0.85, rely=0.01)
|
76
|
+
|
77
|
+
titleLabel2 = tkinter.Label(canvas1, text="こんにちは。前室在庫管理システムです。", font=('BIZ UDゴシック', '25', 'bold'), bg="misty rose",
|
78
|
+
|
79
|
+
fg='firebrick4') # テキスト
|
80
|
+
|
81
|
+
titleLabel2.place(relx=0.29, rely=0.25)
|
82
|
+
|
83
|
+
titleLabel3 = tkinter.Label(canvas1, text="下記ボックスにカーソルを置いて,別紙の社員QRコードをかざしてログインしてください。", font=('BIZ UDゴシック', '15'),
|
84
|
+
|
85
|
+
fg='gray4') # テキスト
|
86
|
+
|
87
|
+
titleLabel3.place(relx=0.23, rely=0.35)
|
88
|
+
|
89
|
+
titleLabel4 = tkinter.Label(canvas1, text="↓Name Here↓", font=('BIZ UDゴシック', '23'), fg='gray4') # テキスト
|
90
|
+
|
91
|
+
titleLabel4.place(relx=0.42, rely=0.42)
|
92
|
+
|
93
|
+
button = tkinter.Button(canvas1, text=" Go ", font=('BIZ UDゴシック', '15'),
|
94
|
+
|
95
|
+
command=lambda: transition_button1(canvas1), fg='gray4') # 遷移ボタン
|
96
|
+
|
97
|
+
button.place(relx=0.45, rely=0.53)
|
98
|
+
|
99
|
+
entry1 = tkinter.Entry(canvas1, font=('Helvetica', '20')) # エントリーボックス
|
100
|
+
|
101
|
+
entry1.place(relx=0.39, rely=0.47)
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
# button実行結果
|
108
|
+
|
109
|
+
def transition_button1(widget):
|
110
|
+
|
111
|
+
widget.place_forget() # canvas(widget)を隠す
|
112
|
+
|
113
|
+
global entry1
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
# 遷移後の画面の作成(画面2)
|
118
|
+
|
119
|
+
canvas2 = tkinter.Canvas(bd=0, width=1366, height=1500) # キャンバス
|
120
|
+
|
121
|
+
canvas2.place(x=0, y=0)
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
# Top Widget上に Scrollbar を生成して配置
|
126
|
+
|
127
|
+
bar = tk.Scrollbar(window, orient=tk.VERTICAL)
|
128
|
+
|
129
|
+
bar.pack(side=tk.RIGHT, fill=tk.Y)
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
# Scrollbarの設定
|
134
|
+
|
135
|
+
bar.config(command=canvas2.yview) # ScrollbarでCanvasを制御
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
# Canvas Widget をTopWidget上に配置
|
140
|
+
|
141
|
+
canvas2.config(yscrollcommand=bar.set) # Canvasのサイズ変更をScrollbarに通知
|
142
|
+
|
143
|
+
canvas2.config(scrollregion=(0, 0, 4800, 4800)) # スクロール範囲
|
144
|
+
|
145
|
+
canvas2.bind_all("<MouseWheel>", lambda eve: canvas2.yview_scroll(int(-eve.delta / 120), 'units'))
|
146
|
+
|
147
|
+
canvas2.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
# Frame Widgetを 生成
|
152
|
+
|
153
|
+
frame = tk.Frame(canvas2)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
# Frame Widgetを Canvas Widget上に配置()
|
158
|
+
|
159
|
+
canvas2.create_window((0, 0), window=frame, anchor=tk.NW, width=1366, height=4800)
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
# ブックを取得
|
164
|
+
|
165
|
+
book = openpyxl.load_workbook(r'C:\Users\mn-manabe\PycharmProjects\sample2Project\一覧備品.xlsx')
|
166
|
+
|
167
|
+
sheet = book['Sheet1']
|
168
|
+
|
169
|
+
titleLabel_1 = tk.Label(canvas2, text=" 出庫したい備品の個数を指定して「出庫」ボタンを押してください。 ",
|
170
|
+
|
171
|
+
font=('BIZ UDゴシック', '15'), bg="misty rose", fg='gray4')
|
172
|
+
|
173
|
+
titleLabel_1.place(relx=0.43, rely=0.018) # これはとどめておく
|
174
|
+
|
175
|
+
t0 = st.Text(width=90, height=40)
|
176
|
+
|
177
|
+
t0.place(relx=0.48, rely=0.13)
|
178
|
+
|
179
|
+
NameLabel = tkinter.Label(canvas2, text=entry1.get() + 'さんがログイン中です', font=('BIZ UDゴシック', '12'), fg='red')
|
180
|
+
|
181
|
+
NameLabel.place(relx=0.43, rely=0.08)
|
182
|
+
|
183
|
+
kakutei_button = tk.Button(canvas2, text=" 出 庫 ", font=('BIZ UDゴシック', '13'), fg='red',
|
184
|
+
|
185
|
+
command=lambda: Kakutei(canvas2))
|
186
|
+
|
187
|
+
kakutei_button.place(relx=0.65, rely=0.87)
|
188
|
+
|
189
|
+
Daimei_Label = tk.Label(canvas2, text="備品名 総個数 必要個数",
|
190
|
+
|
191
|
+
font=('BIZ UDゴシック', '20'), fg='maroon')
|
192
|
+
|
193
|
+
Daimei_Label.place(relx=0.03, rely=0.01)
|
194
|
+
|
195
|
+
# Body
|
196
|
+
|
197
|
+
f1 = open('excel行数.txt', 'w')
|
198
|
+
|
199
|
+
print(sheet.max_row, file=f1)
|
200
|
+
|
201
|
+
f1.close()
|
202
|
+
|
203
|
+
f1 = open('excel行数.txt')
|
204
|
+
|
205
|
+
data1 = f1.read()
|
206
|
+
|
207
|
+
item1 = []
|
208
|
+
|
209
|
+
for cell in sheet['A']:
|
210
|
+
|
211
|
+
item1.append(cell.value)
|
212
|
+
|
213
|
+
item2 = []
|
214
|
+
|
215
|
+
for cell in sheet['B']:
|
216
|
+
|
217
|
+
item2.append(cell.value)
|
218
|
+
|
219
|
+
spinboxes = []
|
220
|
+
|
221
|
+
spinbox_values = []
|
222
|
+
|
223
|
+
for x in range(int(data1)):
|
224
|
+
|
225
|
+
# name
|
226
|
+
|
227
|
+
n = Label(frame, text=item1[x], font=('BIZ UDゴシック', '12'))
|
228
|
+
|
229
|
+
n.place(x=50, y=36 * int(x) + 40)
|
230
|
+
|
231
|
+
# namevalue
|
232
|
+
|
233
|
+
v = Label(frame, text=item2[x], font=('BIZ UDゴシック', '12'))
|
234
|
+
|
235
|
+
v.place(x=265, y=36 * int(x) + 40)
|
236
|
+
|
237
|
+
val = StringVar()
|
238
|
+
|
239
|
+
val.set('0')
|
240
|
+
|
241
|
+
s = ttk.Spinbox(
|
242
|
+
|
243
|
+
frame,
|
244
|
+
|
245
|
+
format='%1.0f',
|
246
|
+
|
247
|
+
state='readonly',
|
248
|
+
|
249
|
+
textvariable=val,
|
250
|
+
|
251
|
+
from_=0,
|
252
|
+
|
253
|
+
to=5,
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
)
|
258
|
+
|
259
|
+
s.place(x=365, y=36 * int(x) + 40)
|
260
|
+
|
261
|
+
spinbox_values.append(val)
|
262
|
+
|
263
|
+
spinboxes.append(val)
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
print(spinboxes)
|
268
|
+
|
269
|
+
def onIncrement():
|
270
|
+
|
271
|
+
print('増')
|
272
|
+
|
273
|
+
sp = [int(s.get()) for s in spinboxes]
|
274
|
+
|
275
|
+
print(sp)
|
276
|
+
|
277
|
+
for x in range(int(data1)):
|
278
|
+
|
279
|
+
if sp[x] > 0:
|
280
|
+
|
281
|
+
itemname = sheet.cell(row=x + 1, column=1).value
|
282
|
+
|
283
|
+
itemvalue = sheet.cell(row=x + 1, column=2).value
|
284
|
+
|
285
|
+
if sp[x] == 1:
|
286
|
+
|
287
|
+
t0.insert(tk.END, '{}:'.format(itemname))
|
288
|
+
|
289
|
+
t0.insert(tk.END, '{}\n'.format(itemvalue))
|
290
|
+
|
291
|
+
def onDecrement(event):
|
292
|
+
|
293
|
+
print('減')
|
294
|
+
|
295
|
+
sp = [int(s.get()) for s in spinboxes]
|
296
|
+
|
297
|
+
print(sp)
|
298
|
+
|
299
|
+
for x in range(int(data1)):
|
300
|
+
|
301
|
+
if sp[x] > 0:
|
302
|
+
|
303
|
+
itemname = sheet.cell(row=x + 1, column=1).value
|
304
|
+
|
305
|
+
itemvalue = sheet.cell(row=x + 1, column=2).value
|
306
|
+
|
307
|
+
if sp[x] == 1:
|
308
|
+
|
309
|
+
pass
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
s.bind("<<Increment>>", onIncrement)
|
316
|
+
|
317
|
+
s.bind("<<Decrement>>", onDecrement)
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
def Kakutei(widget):
|
322
|
+
|
323
|
+
sp = [int(s.get()) for s in spinboxes]
|
324
|
+
|
325
|
+
for x in range(int(data1)):
|
326
|
+
|
327
|
+
if sp[x] > 0:
|
328
|
+
|
329
|
+
itemvalue = sheet.cell(row=x + 1, column=2).value
|
330
|
+
|
331
|
+
total = itemvalue - sp[x]
|
332
|
+
|
333
|
+
sheet.cell(row=x + 1, column=2).value = total
|
334
|
+
|
335
|
+
book.save(r'C:\Users\mn-manabe\PycharmProjects\sample2Project\一覧備品.xlsx')
|
336
|
+
|
337
|
+
book.close()
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
def transition_button2(widget):
|
342
|
+
|
343
|
+
canvas2.pack_forget()
|
344
|
+
|
345
|
+
bar.destroy()
|
346
|
+
|
347
|
+
canvas1.place(x=0, y=0) # キャンバス
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
if __name__ == "__main__":
|
354
|
+
|
355
|
+
# @で画面を閉じる
|
356
|
+
|
357
|
+
def process_b():
|
358
|
+
|
359
|
+
sys.exit()
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
def key(event):
|
366
|
+
|
367
|
+
if event.char == "@":
|
368
|
+
|
369
|
+
process_b()
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
window.bind("<Key>", key)
|
376
|
+
|
377
|
+
window.focus_set()
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
window.mainloop()
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
```
|