回答編集履歴
1
追記・おまけの追加
test
CHANGED
@@ -16,4 +16,94 @@
|
|
16
16
|
|
17
17
|
これを入れると割り込みができます。
|
18
18
|
|
19
|
-
これでもできない場合はまた教えてください。
|
19
|
+
これでもできない場合はまた教えてください。(ファイル名等は適切に置き換えてください)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
## 追記
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
以下のプログラム(最小プログラム)実行してみてください(以下のサイトを参考)
|
28
|
+
|
29
|
+
[https://shizenkarasuzon.hatenablog.com/entry/2019/02/23/151418](https://shizenkarasuzon.hatenablog.com/entry/2019/02/23/151418)
|
30
|
+
|
31
|
+
```python
|
32
|
+
|
33
|
+
from pygame.locals import *
|
34
|
+
|
35
|
+
import pygame
|
36
|
+
|
37
|
+
import sys
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
def main():
|
42
|
+
|
43
|
+
pygame.init() # Pygameを初期化
|
44
|
+
|
45
|
+
screen = pygame.display.set_mode((400, 330)) # 画面を作成
|
46
|
+
|
47
|
+
pygame.display.set_caption("Pygame sample app") # タイトルを作成
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
running = True
|
52
|
+
|
53
|
+
#メインループ
|
54
|
+
|
55
|
+
while running:
|
56
|
+
|
57
|
+
screen.fill((0,0,0)) #画面を黒で塗りつぶす
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
# 画像を描画
|
62
|
+
|
63
|
+
#--------------- 1.画像を読み込む --------------------------
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
#一部の色を透明にする
|
68
|
+
|
69
|
+
img = pygame.image.load("test.jpg").convert()
|
70
|
+
|
71
|
+
colorkey = img.get_at((0,0))
|
72
|
+
|
73
|
+
img.set_colorkey(colorkey, RLEACCEL)
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
#--------------- 2.画像を表示 --------------------------
|
78
|
+
|
79
|
+
screen.blit(img, (0,0))
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
pygame.display.update() #描画処理を実行
|
84
|
+
|
85
|
+
for event in pygame.event.get():
|
86
|
+
|
87
|
+
if event.type == QUIT: # 終了イベント
|
88
|
+
|
89
|
+
running = False
|
90
|
+
|
91
|
+
pygame.quit() #pygameのウィンドウを閉じる
|
92
|
+
|
93
|
+
sys.exit() #システム終了
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
if __name__=="__main__":
|
98
|
+
|
99
|
+
main()
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
## おまけ
|
106
|
+
|
107
|
+
ボタン等の割り込み(イベント処理)は`for event in pygame.event.get()`内で行います。具体的な使い方等はpygame docsのkeyというところにあるのですが、(日本語翻訳版あり)こちらのサイトがわかりやすいかもです。
|
108
|
+
|
109
|
+
[https://sodocumentation.net/ja/pygame/topic/5110/%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E5%87%A6%E7%90%86](https://sodocumentation.net/ja/pygame/topic/5110/%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E5%87%A6%E7%90%86)
|