質問編集履歴
1
変更後のコードと画像
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,11 +24,225 @@
|
|
24
24
|
|
25
25
|
```python
|
26
26
|
|
27
|
-
#先に表示させるウィンドウ
|
28
|
-
|
29
27
|
import tkinter
|
30
28
|
|
31
|
-
|
29
|
+
def create_window():
|
30
|
+
|
31
|
+
import random
|
32
|
+
|
33
|
+
D = random.randint(0,5)
|
34
|
+
|
35
|
+
#ウィンドウ作成
|
36
|
+
|
37
|
+
root = tkinter.Tk()
|
38
|
+
|
39
|
+
root.title("運勢占い")
|
40
|
+
|
41
|
+
root.minsize(640, 480)
|
42
|
+
|
43
|
+
root.option_add("*font", ["MS Pゴシック", 22])
|
44
|
+
|
45
|
+
#画像読み込み
|
46
|
+
|
47
|
+
getu = tkinter.PhotoImage(file="大吉.png")
|
48
|
+
|
49
|
+
ka = tkinter.PhotoImage(file="凶.png")
|
50
|
+
|
51
|
+
sui = tkinter.PhotoImage(file="吉.png")
|
52
|
+
|
53
|
+
moku = tkinter.PhotoImage(file="小吉.png")
|
54
|
+
|
55
|
+
#画像表示
|
56
|
+
|
57
|
+
canvas = tkinter.Canvas(bg="plum", width=640, height=480)
|
58
|
+
|
59
|
+
canvas.place(x=0, y=0)
|
60
|
+
|
61
|
+
img = tkinter.PhotoImage(file="神社.png")
|
62
|
+
|
63
|
+
canvas.create_image(320, 240, image=img)
|
64
|
+
|
65
|
+
#ラベル01
|
66
|
+
|
67
|
+
question1 = tkinter.Label(text="あなたが入力した数字で今日の運勢を占います。", bg="plum")
|
68
|
+
|
69
|
+
question1.place(x=20, y=23)
|
70
|
+
|
71
|
+
question2 = tkinter.Label(text="を↓に入力してください。", bg="plum")
|
72
|
+
|
73
|
+
question2.place(x=279, y=60)
|
74
|
+
|
75
|
+
question3 = tkinter.Label(text="0~10の数字",fg="red", bg="plum")
|
76
|
+
|
77
|
+
question3.place(x=117, y=60)
|
78
|
+
|
79
|
+
#入力ボックス
|
80
|
+
|
81
|
+
entry = tkinter.Entry(width=2, bd=4, bg="#f9f948")
|
82
|
+
|
83
|
+
entry.place(x=300, y=140)
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
#決定ボタン
|
88
|
+
|
89
|
+
button = tkinter.Button(text="占うボタン",bd=3, bg="#e0a3ff")
|
90
|
+
|
91
|
+
button.place(x=240, y=400)
|
92
|
+
|
93
|
+
#おみくじ始まり
|
94
|
+
|
95
|
+
def btn_click():
|
96
|
+
|
97
|
+
a = float(entry.get())
|
98
|
+
|
99
|
+
if a > 10:
|
100
|
+
|
101
|
+
again_text = tkinter.Label(text="0から10の数字を入力してください。",fg="red",bg="plum")
|
102
|
+
|
103
|
+
again_text.place(x=105,y=30)
|
104
|
+
|
105
|
+
question1.destroy()
|
106
|
+
|
107
|
+
question2.destroy()
|
108
|
+
|
109
|
+
question3.destroy()
|
110
|
+
|
111
|
+
return
|
112
|
+
|
113
|
+
if a < 0:
|
114
|
+
|
115
|
+
again_text = tkinter.Label(text="0から10の数字を入力してください。",fg="red",bg="plum")
|
116
|
+
|
117
|
+
again_text.place(x=105,y=30)
|
118
|
+
|
119
|
+
question1.destroy()
|
120
|
+
|
121
|
+
question2.destroy()
|
122
|
+
|
123
|
+
question3.destroy()
|
124
|
+
|
125
|
+
return
|
126
|
+
|
127
|
+
if a+D == 8 or a+D == 9:
|
128
|
+
|
129
|
+
again_text = tkinter.Label(text=" ",fg="red",bg="plum")
|
130
|
+
|
131
|
+
again_text.place(x=100,y=30)
|
132
|
+
|
133
|
+
res_text = tkinter.Label(text="あなたの今日の運勢は大吉です。",fg="red", bg="plum")
|
134
|
+
|
135
|
+
res_text.place(x=115, y=20)
|
136
|
+
|
137
|
+
res_text = tkinter.Label(text="やったね!", bg="plum")
|
138
|
+
|
139
|
+
res_text.place(x=250, y=425)
|
140
|
+
|
141
|
+
canvas.delete("all")
|
142
|
+
|
143
|
+
question1.destroy()
|
144
|
+
|
145
|
+
question2.destroy()
|
146
|
+
|
147
|
+
question3.destroy()
|
148
|
+
|
149
|
+
entry.destroy()
|
150
|
+
|
151
|
+
button.destroy()
|
152
|
+
|
153
|
+
canvas.create_image(320, 240, image=getu)
|
154
|
+
|
155
|
+
if 10 <= a+D <= 15:
|
156
|
+
|
157
|
+
again_text = tkinter.Label(text=" ",fg="red",bg="plum")
|
158
|
+
|
159
|
+
again_text.place(x=100,y=30)
|
160
|
+
|
161
|
+
res_text = tkinter.Label(text="あなたの今日の運勢は凶です。",fg="darkviolet",bg="plum")
|
162
|
+
|
163
|
+
res_text.place(x=120, y=20)
|
164
|
+
|
165
|
+
res_text = tkinter.Label(text="ざんねーん", bg="plum")
|
166
|
+
|
167
|
+
res_text.place(x=250, y=425)
|
168
|
+
|
169
|
+
canvas.delete("all")
|
170
|
+
|
171
|
+
question1.destroy()
|
172
|
+
|
173
|
+
question2.destroy()
|
174
|
+
|
175
|
+
question3.destroy()
|
176
|
+
|
177
|
+
entry.destroy()
|
178
|
+
|
179
|
+
button.destroy()
|
180
|
+
|
181
|
+
canvas.create_image(320, 240, image=ka)
|
182
|
+
|
183
|
+
if 4 <= a+D <= 7:
|
184
|
+
|
185
|
+
again_text = tkinter.Label(text=" ",fg="red",bg="plum")
|
186
|
+
|
187
|
+
again_text.place(x=100,y=30)
|
188
|
+
|
189
|
+
res_text = tkinter.Label(text="あなたの今日の運勢は吉です。",fg="green",bg="plum")
|
190
|
+
|
191
|
+
res_text.place(x=120, y=24)
|
192
|
+
|
193
|
+
res_text = tkinter.Label(text="おっええやん", bg="plum")
|
194
|
+
|
195
|
+
res_text.place(x=240, y=430)
|
196
|
+
|
197
|
+
canvas.delete("all")
|
198
|
+
|
199
|
+
question1.destroy()
|
200
|
+
|
201
|
+
question2.destroy()
|
202
|
+
|
203
|
+
question3.destroy()
|
204
|
+
|
205
|
+
entry.destroy()
|
206
|
+
|
207
|
+
button.destroy()
|
208
|
+
|
209
|
+
canvas.create_image(320, 245, image=sui)
|
210
|
+
|
211
|
+
if 0 <= a+D <= 3:
|
212
|
+
|
213
|
+
again_text = tkinter.Label(text=" ",fg="red",bg="plum")
|
214
|
+
|
215
|
+
again_text.place(x=100,y=30)
|
216
|
+
|
217
|
+
res_text = tkinter.Label(text="あなたの今日の運勢は小吉です。",fg="sienna",bg="plum")
|
218
|
+
|
219
|
+
res_text.place(x=120, y=20)
|
220
|
+
|
221
|
+
res_text = tkinter.Label(text="いいじゃん!", bg="plum")
|
222
|
+
|
223
|
+
res_text.place(x=243, y=425)
|
224
|
+
|
225
|
+
canvas.delete("all")
|
226
|
+
|
227
|
+
question1.destroy()
|
228
|
+
|
229
|
+
question2.destroy()
|
230
|
+
|
231
|
+
question3.destroy()
|
232
|
+
|
233
|
+
entry.destroy()
|
234
|
+
|
235
|
+
button.destroy()
|
236
|
+
|
237
|
+
canvas.create_image(320, 240, image=moku)
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
button["command"] = btn_click
|
242
|
+
|
243
|
+
root.mainloop()
|
244
|
+
|
245
|
+
|
32
246
|
|
33
247
|
root = tkinter.Tk()
|
34
248
|
|
@@ -58,250 +272,30 @@
|
|
58
272
|
|
59
273
|
|
60
274
|
|
275
|
+
button = tkinter.Button(text = "次へ" ,bd = 3, bg= "black", fg="#3374ff", command=create_window)
|
276
|
+
|
277
|
+
button.place(x=280, y=370)
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
root.mainloop()
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
```
|
286
|
+
|
287
|
+
###追記
|
288
|
+
|
289
|
+
![イメージ説明](bd9b04e3a83c6d793a15ba8f343e4ca9.png)
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
### 試したこと
|
294
|
+
|
61
295
|
button = tkinter.Button(text = "次へ" ,bd = 3, bg= "black", fg="#3374ff")
|
62
296
|
|
63
297
|
button.place(x=280, y=370)
|
64
298
|
|
65
|
-
|
66
|
-
|
67
|
-
root.mainloop()
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#ボタンが押された後に表示したいウィンドウ
|
76
|
-
|
77
|
-
import tkinter
|
78
|
-
|
79
|
-
#数字をランダム出力
|
80
|
-
|
81
|
-
import random
|
82
|
-
|
83
|
-
D = random.randint(0,5)
|
84
|
-
|
85
|
-
#ウィンドウ作成
|
86
|
-
|
87
|
-
root = tkinter.Tk()
|
88
|
-
|
89
|
-
root.title("運勢占い")
|
90
|
-
|
91
|
-
root.minsize(640, 480)
|
92
|
-
|
93
|
-
root.option_add("*font", ["MS Pゴシック", 22])
|
94
|
-
|
95
|
-
#画像読み込み
|
96
|
-
|
97
|
-
getu = tkinter.PhotoImage(file="大吉.png")
|
98
|
-
|
99
|
-
ka = tkinter.PhotoImage(file="凶.png")
|
100
|
-
|
101
|
-
sui = tkinter.PhotoImage(file="吉.png")
|
102
|
-
|
103
|
-
moku = tkinter.PhotoImage(file="小吉.png")
|
104
|
-
|
105
|
-
#画像表示
|
106
|
-
|
107
|
-
canvas = tkinter.Canvas(bg="plum", width=640, height=480)
|
108
|
-
|
109
|
-
canvas.place(x=0, y=0)
|
110
|
-
|
111
|
-
img = tkinter.PhotoImage(file="神社.png")
|
112
|
-
|
113
|
-
canvas.create_image(320, 240, image=img)
|
114
|
-
|
115
|
-
#ラベル01
|
116
|
-
|
117
|
-
question1 = tkinter.Label(text="あなたが入力した数字で今日の運勢を占います。", bg="plum")
|
118
|
-
|
119
|
-
question1.place(x=20, y=23)
|
120
|
-
|
121
|
-
question2 = tkinter.Label(text="を↓に入力してください。", bg="plum")
|
122
|
-
|
123
|
-
question2.place(x=279, y=60)
|
124
|
-
|
125
|
-
question3 = tkinter.Label(text="0~10の数字",fg="red", bg="plum")
|
126
|
-
|
127
|
-
question3.place(x=117, y=60)
|
128
|
-
|
129
|
-
#入力ボックス
|
130
|
-
|
131
|
-
entry = tkinter.Entry(width=2, bd=4, bg="#f9f948")
|
132
|
-
|
133
|
-
entry.place(x=300, y=140)
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
#決定ボタン
|
138
|
-
|
139
|
-
button = tkinter.Button(text="占うボタン",bd=3, bg="#e0a3ff")
|
140
|
-
|
141
|
-
button.place(x=240, y=400)
|
142
|
-
|
143
|
-
#おみくじ始まり
|
144
|
-
|
145
|
-
def btn_click():
|
146
|
-
|
147
|
-
a = float(entry.get())
|
148
|
-
|
149
|
-
if a > 10:
|
150
|
-
|
151
|
-
again_text = tkinter.Label(text="0から10の数字を入力してください。",fg="red",bg="plum")
|
152
|
-
|
153
|
-
again_text.place(x=105,y=30)
|
154
|
-
|
155
|
-
question1.destroy()
|
156
|
-
|
157
|
-
question2.destroy()
|
158
|
-
|
159
|
-
question3.destroy()
|
160
|
-
|
161
|
-
return
|
162
|
-
|
163
|
-
if a < 0:
|
164
|
-
|
165
|
-
again_text = tkinter.Label(text="0から10の数字を入力してください。",fg="red",bg="plum")
|
166
|
-
|
167
|
-
again_text.place(x=105,y=30)
|
168
|
-
|
169
|
-
question1.destroy()
|
170
|
-
|
171
|
-
question2.destroy()
|
172
|
-
|
173
|
-
question3.destroy()
|
174
|
-
|
175
|
-
return
|
176
|
-
|
177
|
-
if a+D == 8 or a+D == 9:
|
178
|
-
|
179
|
-
again_text = tkinter.Label(text=" ",fg="red",bg="plum")
|
180
|
-
|
181
|
-
again_text.place(x=100,y=30)
|
182
|
-
|
183
|
-
res_text = tkinter.Label(text="あなたの今日の運勢は大吉です。",fg="red", bg="plum")
|
184
|
-
|
185
|
-
res_text.place(x=115, y=20)
|
186
|
-
|
187
|
-
res_text = tkinter.Label(text="やったね!", bg="plum")
|
188
|
-
|
189
|
-
res_text.place(x=250, y=425)
|
190
|
-
|
191
|
-
canvas.delete("all")
|
192
|
-
|
193
|
-
question1.destroy()
|
194
|
-
|
195
|
-
question2.destroy()
|
196
|
-
|
197
|
-
question3.destroy()
|
198
|
-
|
199
|
-
entry.destroy()
|
200
|
-
|
201
|
-
button.destroy()
|
202
|
-
|
203
|
-
canvas.create_image(320, 240, image=getu)
|
204
|
-
|
205
|
-
if 10 <= a+D <= 15:
|
206
|
-
|
207
|
-
again_text = tkinter.Label(text=" ",fg="red",bg="plum")
|
208
|
-
|
209
|
-
again_text.place(x=100,y=30)
|
210
|
-
|
211
|
-
res_text = tkinter.Label(text="あなたの今日の運勢は凶です。",fg="darkviolet",bg="plum")
|
212
|
-
|
213
|
-
res_text.place(x=120, y=20)
|
214
|
-
|
215
|
-
res_text = tkinter.Label(text="ざんねーん", bg="plum")
|
216
|
-
|
217
|
-
res_text.place(x=250, y=425)
|
218
|
-
|
219
|
-
canvas.delete("all")
|
220
|
-
|
221
|
-
question1.destroy()
|
222
|
-
|
223
|
-
question2.destroy()
|
224
|
-
|
225
|
-
question3.destroy()
|
226
|
-
|
227
|
-
entry.destroy()
|
228
|
-
|
229
|
-
button.destroy()
|
230
|
-
|
231
|
-
canvas.create_image(320, 240, image=ka)
|
232
|
-
|
233
|
-
if 4 <= a+D <= 7:
|
234
|
-
|
235
|
-
again_text = tkinter.Label(text=" ",fg="red",bg="plum")
|
236
|
-
|
237
|
-
again_text.place(x=100,y=30)
|
238
|
-
|
239
|
-
res_text = tkinter.Label(text="あなたの今日の運勢は吉です。",fg="green",bg="plum")
|
240
|
-
|
241
|
-
res_text.place(x=120, y=24)
|
242
|
-
|
243
|
-
res_text = tkinter.Label(text="おっええやん", bg="plum")
|
244
|
-
|
245
|
-
res_text.place(x=240, y=430)
|
246
|
-
|
247
|
-
canvas.delete("all")
|
248
|
-
|
249
|
-
question1.destroy()
|
250
|
-
|
251
|
-
question2.destroy()
|
252
|
-
|
253
|
-
question3.destroy()
|
254
|
-
|
255
|
-
entry.destroy()
|
256
|
-
|
257
|
-
button.destroy()
|
258
|
-
|
259
|
-
canvas.create_image(320, 245, image=sui)
|
260
|
-
|
261
|
-
if 0 <= a+D <= 3:
|
262
|
-
|
263
|
-
again_text = tkinter.Label(text=" ",fg="red",bg="plum")
|
264
|
-
|
265
|
-
again_text.place(x=100,y=30)
|
266
|
-
|
267
|
-
res_text = tkinter.Label(text="あなたの今日の運勢は小吉です。",fg="sienna",bg="plum")
|
268
|
-
|
269
|
-
res_text.place(x=120, y=20)
|
270
|
-
|
271
|
-
res_text = tkinter.Label(text="いいじゃん!", bg="plum")
|
272
|
-
|
273
|
-
res_text.place(x=243, y=425)
|
274
|
-
|
275
|
-
canvas.delete("all")
|
276
|
-
|
277
|
-
question1.destroy()
|
278
|
-
|
279
|
-
question2.destroy()
|
280
|
-
|
281
|
-
question3.destroy()
|
282
|
-
|
283
|
-
entry.destroy()
|
284
|
-
|
285
|
-
button.destroy()
|
286
|
-
|
287
|
-
canvas.create_image(320, 240, image=moku)
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
button["command"] = btn_click
|
292
|
-
|
293
|
-
root.mainloop()
|
294
|
-
|
295
|
-
```
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
### 試したこと
|
300
|
-
|
301
|
-
button = tkinter.Button(text = "次へ" ,bd = 3, bg= "black", fg="#3374ff")
|
302
|
-
|
303
|
-
button.place(x=280, y=370)
|
304
|
-
|
305
299
|
の後にdef文を書いてみようと思いましたが、どんな風に書いたらいいか分からずここに聞きました。甘い考えですみません。
|
306
300
|
|
307
301
|
|