質問編集履歴

3

2020/10/28 07:12

投稿

tarakun
tarakun

スコア22

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- Pythonの画面遷移ができません(本当の初心者です)
1
+ > 引用テキストPythonの画面遷移ができません(本当の初心者です)
2
2
 
3
3
 
4
4
 
@@ -35,189 +35,3 @@
35
35
  ```
36
36
 
37
37
  Python
38
-
39
- コード
40
-
41
- ```
42
-
43
- import tkinter
44
-
45
- import Game
46
-
47
-
48
-
49
-
50
-
51
- def openning():
52
-
53
- global canvas
54
-
55
- canvas.destroy()
56
-
57
- canvas = tkinter.Canvas(root, width = 600, height = 800)
58
-
59
- canvas.create_image(960, 540, image = images[0], tag = "open")
60
-
61
- canvas.pack()
62
-
63
-
64
-
65
- button = tkinter.Button(root, text = "ゲームスタート", bg = "black", fg = "white")
66
-
67
- scbutton = tkinter.Button(root, text = " スコア ", bg = "black", fg = "white")
68
-
69
- button.place(x = 170, y = 450)
70
-
71
- scbutton.place(x = 190, y = 600)
72
-
73
- button["command"] = difficulty_selection
74
-
75
- scbutton["command"] = score
76
-
77
-
78
-
79
- def difficulty_selection():
80
-
81
- global canvas
82
-
83
- canvas.destroy()
84
-
85
- canvas = tkinter.Canvas(root, width = 600, height = 800)
86
-
87
- canvas.create_image(960, 540, image = images[1], tag = "result")
88
-
89
- canvas.pack()
90
-
91
-
92
-
93
- esbutton = tkinter.Button(root, text = " easy ", bg = "black", fg = "white")
94
-
95
- hdbutton = tkinter.Button(root, text = " hard ", bg = "black", fg = "white")
96
-
97
- edbutton = tkinter.Button(root,text = "endlesshard", bg = "black", fg = "white")
98
-
99
- stbutton = tkinter.Button(root,text = "最初に戻る", bg = "black", fg = "white")
100
-
101
- esbutton.place(x = 215, y = 375)
102
-
103
- hdbutton.place(x = 215, y = 475)
104
-
105
- edbutton.place(x = 190, y = 575)
106
-
107
- stbutton.place(x = 200, y = 675)
108
-
109
- esbutton["command"] = easy
110
-
111
- hdbutton["command"] = hard
112
-
113
- edbutton["command"] = endlesshard
114
-
115
- stbutton["command"] = openning
116
-
117
-
118
-
119
- def easy():
120
-
121
- Game()
122
-
123
-
124
-
125
- def hard():
126
-
127
- global canvas
128
-
129
- canvas.destroy()
130
-
131
- canvas = tkinter.Canvas(root, width = 600, height = 800)
132
-
133
- canvas.create_image(960, 540, image = images[3], tag = "open")
134
-
135
- canvas.pack()
136
-
137
-
138
-
139
- esbutton = tkinter.Button(root, text = "最初に戻る", bg = "black", fg = "white")
140
-
141
- esbutton.place(x = 200, y = 675)
142
-
143
- esbutton["command"] = openning
144
-
145
-
146
-
147
- def endlesshard():
148
-
149
- global canvas
150
-
151
- canvas.destroy()
152
-
153
- canvas = tkinter.Canvas(root, width = 600, height = 800)
154
-
155
- canvas.create_image(960, 540, image = images[4], tag = "open")
156
-
157
- canvas.pack()
158
-
159
-
160
-
161
- esbutton = tkinter.Button(root, text = "最初に戻る", bg = "black", fg = "white")
162
-
163
- esbutton.place(x = 200, y = 675)
164
-
165
- esbutton["command"] = openning
166
-
167
-
168
-
169
- def score():
170
-
171
- global canvas
172
-
173
- canvas.destroy()
174
-
175
- canvas = tkinter.Canvas(root, width = 600, height = 800)
176
-
177
- canvas.create_image(960, 540, image = images[5], tag = "open")
178
-
179
- canvas.pack()
180
-
181
-
182
-
183
- esbutton = tkinter.Button(root, text = "最初に戻る", bg = "black", fg = "white")
184
-
185
- esbutton.place(x = 200, y = 675)
186
-
187
- esbutton["command"] = openning
188
-
189
-
190
-
191
- root = tkinter.Tk();
192
-
193
- root.title("Game")
194
-
195
- root.minsize(600,800)
196
-
197
- root.option_add("*font", ["メイリオ", 25])
198
-
199
-
200
-
201
- canvas = tkinter.Canvas(root, width = 600, height = 800)
202
-
203
-
204
-
205
- images = [tkinter.PhotoImage(file = "img/スタート画面.png"),
206
-
207
- tkinter.PhotoImage(file = "img/難易度選択.png"),
208
-
209
- tkinter.PhotoImage(file = "img/easy.png"),
210
-
211
- tkinter.PhotoImage(file = "img/hard.png"),
212
-
213
- tkinter.PhotoImage(file = "img/endlesshard.png"),
214
-
215
- tkinter.PhotoImage(file = "img/score.png")]
216
-
217
-
218
-
219
- openning()
220
-
221
-
222
-
223
- root.mainloop()

2

2020/10/28 07:12

投稿

tarakun
tarakun

スコア22

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- 現在pythonを使ってゲームを作っているのですが、難易度を選択する画面からゲームプレイ画面への画面遷移で詰まってしまっています。
5
+ 現在pythonを使ってゲームを作っているのですが、難易度を選択する画面からゲームプレイ画面への画面遷移でかれこれ2週間くらい詰まってしまっています。
6
6
 
7
7
 
8
8
 
@@ -12,6 +12,10 @@
12
12
 
13
13
  ゲーム自体のプログラムは別のファイルにあります。
14
14
 
15
+ ゲームファイルは「Game.py」という名前で、同じフォルダ内に入っています。
16
+
17
+ def easyからゲームファイルに飛んで…と思いましたが、なかなかうまくいきません。
18
+
15
19
 
16
20
 
17
21
  おそらく基本中の基本だと思われますが、いくら調べても理解できません。もうなにをしていいかわからなくなりました。
@@ -86,13 +90,11 @@
86
90
 
87
91
 
88
92
 
89
- #ボタン
90
-
91
93
  esbutton = tkinter.Button(root, text = " easy ", bg = "black", fg = "white")
92
94
 
93
95
  hdbutton = tkinter.Button(root, text = " hard ", bg = "black", fg = "white")
94
96
 
95
- edbutton = tkinter.Button(root,text = "endlesshard", bg = "black", fg = "white") #endlesshard
97
+ edbutton = tkinter.Button(root,text = "endlesshard", bg = "black", fg = "white")
96
98
 
97
99
  stbutton = tkinter.Button(root,text = "最初に戻る", bg = "black", fg = "white")
98
100
 
@@ -100,7 +102,7 @@
100
102
 
101
103
  hdbutton.place(x = 215, y = 475)
102
104
 
103
- edbutton.place(x = 190, y = 575) #endlesshard
105
+ edbutton.place(x = 190, y = 575)
104
106
 
105
107
  stbutton.place(x = 200, y = 675)
106
108
 
@@ -108,7 +110,7 @@
108
110
 
109
111
  hdbutton["command"] = hard
110
112
 
111
- edbutton["command"] = endlesshard #endlesshard
113
+ edbutton["command"] = endlesshard
112
114
 
113
115
  stbutton["command"] = openning
114
116
 
@@ -184,9 +186,7 @@
184
186
 
185
187
  esbutton["command"] = openning
186
188
 
187
-
188
-
189
- #ウィンドウを作る
189
+
190
190
 
191
191
  root = tkinter.Tk();
192
192
 
@@ -198,14 +198,10 @@
198
198
 
199
199
 
200
200
 
201
- #キャンバス
202
-
203
201
  canvas = tkinter.Canvas(root, width = 600, height = 800)
204
202
 
205
203
 
206
204
 
207
- #イメージのファイル読込み
208
-
209
205
  images = [tkinter.PhotoImage(file = "img/スタート画面.png"),
210
206
 
211
207
  tkinter.PhotoImage(file = "img/難易度選択.png"),

1

文法の修正

2020/10/26 09:16

投稿

tarakun
tarakun

スコア22

test CHANGED
File without changes
test CHANGED
@@ -18,6 +18,16 @@
18
18
 
19
19
 
20
20
 
21
+ また、teratail自体も初心者なため説明不足なところあると思いますが補足で追加させていただければと思います。
22
+
23
+ よろしくお願いいたします。
24
+
25
+ ### 試したこと
26
+
27
+ importの仕方を何通りかやってみました。
28
+
29
+ def easy に直接ゲームファイルのプログラムをコピペしましたがうまくいきませんでした。
30
+
21
31
  ```
22
32
 
23
33
  Python