ゴミ箱を空にするショートカットを作成方法
何もないデスクトップ上で、右クリックし「ショートカットの作成」ウィンドウが表示されるので、「項目の場所を入力してください」欄に「C:\Windows\System32\cmd.exe /c "echo Y|PowerShell.exe -NoProfile -Command Clear-RecycleBin"」とコマンドを入力して「次へ」をクリックし名前を、「ゴミ箱を空にする」しましょう。
ゴミ箱を空にする.ps1
# @echo off
# https://qiita.com/sakekasunuts/items/d80ecae428866f9acdaa
# powershell -executionpolicy RemoteSigned -File "%~dp0%~n0.ps1"
# https://qiita.com/_Sasaki_/items/c8486e58df45333017d7
# コマンドを実行するための確認を求められます。
# Clear-RecycleBin -DriveLetter C
# ごみ箱をクリアするための確認を求めるメッセージは表示されません。
#
Clear-RecycleBin -Force
# Windows11でゴミ箱を一瞬で空にするショートカットを作成する手順を紹介
# https://www.bihoku-senior.net/pckobanasi3/238.1.pdf
# https://www.youtube.com/watch?v=gn3TtgaoGjQ
# C:\Windows\System32\cmd.exe /c "echo Y|PowerShell.exe -NoProfile -Command Clear-RecycleBin"
Pythonファイルをバッチファイルへドラッグ&ドロップして、最小化した状態で起動する方法をAI「Gemini」に聞いてみた。
@echo off
setlocal enabledelayedexpansion
rem スクリプトが内部実行されているかを確認
if /i "%~1" NEQ "_INTERNAL_RUN_" (
rem 内部実行でなければ、最小化して内部フラグと全ての引数と共に新しいインスタンスを起動
start /min "" "%~dpnx0" _INTERNAL_RUN_ %*
exit /b
)
rem Python仮想環境をアクティベート
rem Python環境へのパスが正しいことを確認してください(例: venv\Scripts\activate.batなど)
call "..\Scripts\activate.bat"
rem ドラッグ&ドロップされたPythonファイルのパスを格納する変数
set "files_to_run="
rem 最初の引数(_INTERNAL_RUN_)をスキップするためのフラグ
set "skip_first_arg=true"
rem 全ての引数(%*)をループし、最初の引数(_INTERNAL_RUN_)をスキップして残りを処理
for %%A in (%*) do (
if defined skip_first_arg (
rem 最初の引数をスキップし、フラグを解除
set "skip_first_arg="
) else (
rem 残りの引数を files_to_run に追加(フルパスで、スペース対応のためダブルクォーテーションで囲む)
set "files_to_run=!files_to_run! "%%~fA""
)
)
rem スペースで区切られたファイルパスのリストを処理
for %%i in (!files_to_run!) do (
rem ファイルが存在し、かつ拡張子が .py であるかを確認してからPythonで実行
if exist "%%~fi" (
if /i "%%~xi" EQU ".py" (
python "%%~fi"
) else (
echo Warning: "%%~nxi" はPythonスクリプトではないためスキップされました。
)
)
)
exit
pythonのパスbat「!_appliDandD65py実行.bat」「DandDimage5色処理-Pyqt6b6466y.py」欲しい方、声掛けてネ😁
@echo off
rem このバッチファイルは、「はばたき」マット作成用のpythonコードアプリを実行するファイルです。
rem 単体で、移動しても、実行出来るよ!
rem たったの一行で、実行きる凄いコードです。
rem バッチファイルコマンドプロンプトの最小化
rem
start "" /min cmd /c "D:\*****\PyQt6_venv\Scripts\activate.bat && python D:\******\Pyuki\PyQt6_venv\Scripts\DandD65.py"
rem コマンドを使った方法でも出来るよ!
rem 本来であれば、例:python DandD65.py ThemePreview.jpg
rem バッチファイルを使った方法
rem start "" /min cmd /c "D:\******\PyQt6_venv\Scripts\activate.bat && python D:\******\PyQt6_venv\Scripts\DandD65.py ThemePreview.jpg"
rem コマンドを使った方法では、値を自由に変更出来るよ!
rem 値の変更方法:TeraPadで「ファイルを開く」を使い【D:\******\PyQt6_venv\Scripts\ColorXSiz】すぐに開いてに値を入力変更で出来るよ!
rem バッチファイルコマンドプロンプトを通常実行「ドラッグアンドドロップ」
rem call "..\..\Scripts\activate.bat" %* && (for %%i in (%*) do (python %%i)) && pause
rem call "..\..\Scripts\activate.bat" %* && (for %%i in (%*) do (python %%i)) && cmd /k
rem Pythonファイルをバッチファイルへドラッグ&ドロップして、最小化した状態で起動する方法自作
rem start "" /min cmd /c "..\Scripts\activate.bat && (for %%i in (%*) do (python %%i))"
Pythonファイルをバッチファイルへドラッグ&ドロップして最小化した状態で起動する方法をAI「X - Grok」に聞いてみた。
少し回答にウンチクが、あるが、最後に「一つのバッチファイルにしてください。」と、送信するとちゃんと欲しい答えが、返って来た😁
【run_python_minimized.bat】
@echo off
start /min cmd /c "call ""..\Scripts\activate.bat"" && call activate base && for %%i in (%*) do (python %%i)"
バッチファイルでPythonのGUIアプリをドラッグアンドドロップで実行する際に、コマンドプロンプトウィンドウを非表示にする方法をAI「X - Grok」に聞いてみたら、二つのコードを、提出してくれた。
Geminiでは、powshellやvbsやら何たらかんたらでしたが、Grokでは、一発解答でした。😁
【run_python_gui.bat】
@echo off
if "%~1"=="" (
echo No Python scripts provided.
exit /b
)
call "..\Scripts\activate.bat"
for %%i in (%*) do (
start /b pythonw.exe "%%i"
)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
こっちは、もっと、凄かった!ドラッグアンドドロップしても、パス指定で単体起動も両方出来るよ!🥳
【run_gui.bat】
@echo off
set "script=%~1"
if not defined script (
echo No Python script provided.
exit /b
)
call "..\Scripts\activate.bat" && start /b pythonw.exe "%script%"
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
何だかんだで、一行で、出来る様にしてみた!❶🥳
call "..\Scripts\activate.bat" %* && (for %%i in (%*) do (start /b pythonw.exe %%i))
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
何だかんだで、一行で、出来る様にしてみた!❷🥳
call "C:\Wpy642251202\WPhaba\PyQt6_venv\Scripts\activate.bat" %* && (start /b pythonw.exe C:\Wpy64251202\WPhaba\PyQt6_venv\Scripts\DandD65.py)
rem ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem 【ColorXSiz】を使って、コマンドを使った方法でも出来るよ!
rem 本来であれば、例:python DandD65.py imagetest.png
rem 下のコードは、コマンドプロンプトラインでのやり方です。
rem コマンドラインでの実行例:C:\Wpy64251202\WPhaba\PyQt6_venv\Scripts\activate.bat && python C:\Wpy64251202\WPhaba\PyQt6_venv\Scripts\DandD65.py imagetest.png
rem 上のコードを実行すると仮想環境(venv)に入った状態になりす。
rem 仮想環境を抜ける方法は、「deactivate」コマンドを入力するだけです。
rem バッチファイルを使った方法【ColorXSiz】版
rem これは、はばたき作業用アプリです。本体は【DandD65.py】です。
rem ここでは、コマンドを使用しています。【ColorXSiz】の値を変える事で自由にピクセル画像を変更出来ます。
rem 下の、コードは、バッチ(.bat)コードです。そのままで、【ColorXSiz】と共に画像フォルダへ移植して使えますが、
rem 使用の際、末尾の画像ファイル名を変えてください。例:imagetest.png → imagefx.png
start "" /min cmd /c "C:\Wpy64251202\WPhaba\PyQt6_venv\Scripts\activate.bat && python C:\Wpy64251202\WPhaba\PyQt6_venv\Scripts\DandD65.py imagetest.png"
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
@echo off
set "command=call "..\Scripts\activate.bat" %* && (for %%i in (%*) do (start /b pythonw.exe %%i))"
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath 'cmd.exe' -ArgumentList '/c %command%' -WindowStyle Hidden"
Gemini先生と、一緒に作ってみた【GUIReversi.py】です。
import tkinter
import tkinter.messagebox
import random
FS = ("Times New Roman", 30) # フォントサイズは固定 (メッセージ用)
FL = ("Times New Roman", 80) # フォントサイズは固定 (タイトル用)
BLACK = 1
WHITE = 2
mx = 0
my = 0
mc = 0
proc = 0
turn = 0
msg = ""
space = 0 # 空きマスの数。ゲームの進行管理に使用。
color = [0]*2
who = ["うんじゅ", "コンピュータ"]
board = []
for y in range(8):
board.append([0,0,0,0,0,0,0,0])
# --- GUI画面サイズ変更に関連するグローバル変数と定数 ---
# TILE_SIZE は初期値として設定し、CanvasのConfigureイベントで動的に更新されます
TILE_SIZE = 80
MIN_MESSAGE_AREA_HEIGHT = 60 # メッセージ表示エリアに確保する最小高さ (ピクセル単位)
# コンピュータの評価関数で使用するマスの重み付け
WEIGHTS = [
[120, -20, 20, 5, 5, 20, -20, 120],
[-20, -40, -5, -5, -5, -5, -40, -20],
[ 20, -5, 15, 3, 3, 15, -5, 20],
[ 5, -5, 3, 3, 3, 3, -5, 5],
[ 5, -5, 3, 3, 3, 3, -5, 5],
[ 20, -5, 15, 3, 3, 15, -5, 20],
[-20, -40, -5, -5, -5, -5, -40, -20],
[120, -20, 20, 5, 5, 20, -20, 120]
]
# Minimax探索の最大深さ。
MAX_DEPTH = 5
def click(e):
global mx, my, mc
mc = 1
# 現在のTILE_SIZEに基づいてmx, myを計算
# クリックY座標がボードエリア外(メッセージエリア)だった場合を考慮
if e.y < TILE_SIZE * 8: # ボードの範囲内でのみ計算
mx = int(e.x / TILE_SIZE)
my = int(e.y / TILE_SIZE)
else: # ボードエリア外をクリックした場合は無効な座標に
mx = -1
my = -1
# ボードの範囲(0-7)内に収める (無効な場合はそのまま)
if mx > 7: mx = 7
if my > 7: my = 7
def banmen():
cvs.delete("all")
# Canvasの現在の幅と高さを取得。これらの値はconfigureイベントによって更新される
# 初回起動時にはCanvasのpack()が完了するまでは幅/高さが0になる可能性があるため、チェック
current_canvas_width = cvs.winfo_width()
current_canvas_height = cvs.winfo_height()
# メッセージをCanvasの下部中央に動的に配置
# current_canvas_height * 0.95 などの比率を使うと、どんな高さでも下端に近くなる
# または、ボード部分の高さとメッセージ部分の高さの合計で計算する
message_y_pos = min(current_canvas_height - FS[1], TILE_SIZE * 8 + MIN_MESSAGE_AREA_HEIGHT / 2)
cvs.create_text(current_canvas_width/2, message_y_pos, text=msg, fill="silver", font=FS)
# 現在のTILE_SIZEを使用してボードと石を描画
for y in range(8):
for x in range(8):
X = x * TILE_SIZE
Y = y * TILE_SIZE
cvs.create_rectangle(X, Y, X + TILE_SIZE, Y + TILE_SIZE, outline="black")
# 石のサイズはTILE_SIZEに比例して調整
if board[y][x] == BLACK:
cvs.create_oval(X + TILE_SIZE*0.125, Y + TILE_SIZE*0.125, X + TILE_SIZE*0.875, Y + TILE_SIZE*0.875, fill="black", width=0)
if board[y][x] == WHITE:
cvs.create_oval(X + TILE_SIZE*0.125, Y + TILE_SIZE*0.125, X + TILE_SIZE*0.875, Y + TILE_SIZE*0.875, fill="white", width=0)
# proc==0 (タイトル画面) の場合、タイトルと選択肢も描画
if proc == 0:
if current_canvas_width > 0 and current_canvas_height > 0: # Canvasのサイズが有効な場合のみ描画
cvs.create_text(current_canvas_width/2, current_canvas_height*0.3, text="けぇ~さぁ~", fill="gold", font=FL)
# 選択肢のテキストを動的に配置
player_choice_y = current_canvas_height * 0.6
player_choice_left_x = current_canvas_width * 0.25
player_choice_right_x = current_canvas_width * 0.75
cvs.create_text(player_choice_left_x, player_choice_y, text="先手(黒)", fill="lime", font=FS)
cvs.create_text(player_choice_right_x, player_choice_y, text="後手(白)", fill="lime", font=FS)
cvs.update()
def ban_syokika():
global space
space = 60 # 64マス - 初期配置の4マス
for y in range(8):
for x in range(8):
board[y][x] = 0
board[3][4] = BLACK
board[4][3] = BLACK
board[3][3] = WHITE
board[4][4] = WHITE
print_board_to_console(board, "初期盤面")
def ishi_utsu(x, y, iro, current_board_state):
current_board_state[y][x] = iro
for dy in range(-1, 2):
for dx in range(-1, 2):
if dx == 0 and dy == 0:
continue
k = 0
sx = x
sy = y
path_to_flip = []
while True:
sx += dx
sy += dy
if sx < 0 or sx > 7 or sy < 0 or sy > 7:
path_to_flip = []
break
if current_board_state[sy][sx] == 0:
path_to_flip = []
break
if current_board_state[sy][sx] == 3 - iro:
k += 1
path_to_flip.append((sx, sy))
if current_board_state[sy][sx] == iro:
for fx, fy in path_to_flip:
current_board_state[fy][fx] = iro
break
def kaeseru(x, y, iro, current_board_state):
if x < 0 or x > 7 or y < 0 or y > 7: # 無効なクリック座標の場合は-1を返す
return -1
if current_board_state[y][x] > 0:
return -1
total = 0
for dy in range(-1, 2):
for dx in range(-1, 2):
if dx == 0 and dy == 0:
continue
k = 0
sx = x
sy = y
while True:
sx += dx
sy += dy
if sx < 0 or sx > 7 or sy < 0 or sy > 7:
break
if current_board_state[sy][sx] == 0:
break
if current_board_state[sy][sx] == 3 - iro:
k += 1
if current_board_state[sy][sx] == iro:
total += k
break
return total
def uteru_masu(iro, current_board_state):
for y in range(8):
for x in range(8):
if kaeseru(x, y, iro, current_board_state) > 0:
return True
return False
def ishino_kazu(current_board_state):
b = 0
w = 0
for y in range(8):
for x in range(8):
if current_board_state[y][x] == BLACK: b += 1
if current_board_state[y][x] == WHITE: w += 1
return b, w
def deep_copy_board(board_state):
return [row[:] for row in board_state]
def make_move_on_copy(board_state_copy, x, y, iro):
new_board = deep_copy_board(board_state_copy)
ishi_utsu(x, y, iro, new_board)
return new_board
def get_valid_moves(current_board_state, current_player_color):
moves = []
for y in range(8):
for x in range(8):
if kaeseru(x, y, current_player_color, current_board_state) > 0:
moves.append((x, y))
return moves
def evaluate_board(current_board_state, ai_color):
score = 0
opponent_color = 3 - ai_color
empty_spaces = 0
for row in current_board_state:
empty_spaces += row.count(0)
if empty_spaces <= 15:
b, w = ishino_kazu(current_board_state)
if ai_color == BLACK:
score += (b - w) * 1000
else:
score += (w - b) * 1000
return score
for y in range(8):
for x in range(8):
if current_board_state[y][x] == ai_color:
score += WEIGHTS[y][x]
elif current_board_state[y][x] == opponent_color:
score -= WEIGHTS[y][x]
ai_moves = len(get_valid_moves(current_board_state, ai_color))
opponent_moves = len(get_valid_moves(current_board_state, opponent_color))
mobility_score = (ai_moves - opponent_moves) * 10
score += mobility_score
return score
def minimax(current_board_state, depth, is_maximizing_player, alpha, beta, ai_color):
if depth == 0:
return evaluate_board(current_board_state, ai_color)
current_player_color = ai_color if is_maximizing_player else (3 - ai_color)
valid_moves = get_valid_moves(current_board_state, current_player_color)
if not valid_moves:
opponent_color = 3 - current_player_color
if not uteru_masu(opponent_color, current_board_state):
return evaluate_board(current_board_state, ai_color)
else:
return minimax(current_board_state, depth - 1, not is_maximizing_player, alpha, beta, ai_color)
if is_maximizing_player:
max_eval = -float('inf')
for move_x, move_y in valid_moves:
new_board_state = make_move_on_copy(current_board_state, move_x, move_y, current_player_color)
eval = minimax(new_board_state, depth - 1, False, alpha, beta, ai_color)
max_eval = max(max_eval, eval)
alpha = max(alpha, eval)
if beta <= alpha:
break
return max_eval
else:
min_eval = float('inf')
for move_x, move_y in valid_moves:
new_board_state = make_move_on_copy(current_board_state, move_x, move_y, current_player_color)
eval = minimax(new_board_state, depth - 1, True, alpha, beta, ai_color)
min_eval = min(min_eval, eval)
beta = min(beta, eval)
if beta <= alpha:
break
return min_eval
def computer_strongest(ai_color):
best_eval = -float('inf')
valid_moves = get_valid_moves(board, ai_color)
if not valid_moves:
return None, None
candidate_moves = []
for move_x, move_y in valid_moves:
new_board_state = make_move_on_copy(board, move_x, move_y, ai_color)
eval = minimax(new_board_state, MAX_DEPTH - 1, False, -float('inf'), float('inf'), ai_color)
if eval > best_eval:
best_eval = eval
candidate_moves = [(move_x, move_y)]
elif eval == best_eval:
candidate_moves.append((move_x, move_y))
if candidate_moves:
return random.choice(candidate_moves)
else:
return None, None
# コマンドプロンプトに盤面を表示する関数
def print_board_to_console(current_board_state, message=""):
print("\n--- " + message + " ---")
print(" 0 1 2 3 4 5 6 7")
print("-----------------")
for y in range(8):
row_str = str(y) + "|"
for x in range(8):
if current_board_state[y][x] == BLACK:
row_str += "B " # 黒石
elif current_board_state[y][x] == WHITE:
row_str += "W " # 白石
else:
row_str += ". " # 空きマス
print(row_str + "|")
print("-----------------\n")
# --- Canvasサイズ変更時のハンドラ ---
def _on_canvas_configure(event):
global TILE_SIZE
# 現在のCanvasの幅と高さを取得
canvas_width = event.width
canvas_height = event.height
# ボードエリアに使用できる高さを計算 (メッセージエリアの分を引く)
# ここで計算される高さは、ボード全体(8マス分)の高さ
effective_board_height = max(1, canvas_height - MIN_MESSAGE_AREA_HEIGHT)
# 幅と高さの両方からマスのサイズを計算し、小さい方を採用して正方形を維持
# 8マス分の幅と高さなので、各辺を8で割る
potential_tile_size_from_width = canvas_width / 8
potential_tile_size_from_height = effective_board_height / 8
TILE_SIZE = min(potential_tile_size_from_width, potential_tile_size_from_height)
# マスが極端に小さくなるのを防ぐための最小サイズ設定 (任意)
TILE_SIZE = max(10, TILE_SIZE)
# 新しいサイズで盤面を再描画
banmen()
def main():
global mc, proc, turn, msg, space, board
# このmain関数が初めて呼ばれたときに、初期のTILE_SIZEで描画
banmen()
if proc == 0: # タイトル画面
msg = "先手、後手を選んでください"
# タイトル画面の描画は_on_canvas_configure内のbanmen()でも処理される
if mc == 1: # ウィンドウをクリック
mc = 0
# クリック座標が有効な範囲内か確認
if (mx >= 0 and mx <= 7 and my >= 0 and my <= 7):
# プレイヤーの選択範囲の判定も、相対的な位置で判断するように変更することが望ましいが、
# 今回は元のmx, myの範囲を維持 (mx=1or2, my=5 は 左側の2マス、mx=5or6, my=5 は 右側の2マス)
if (mx == 1 or mx == 2) and my == 5: # 先手(黒)の領域をクリック
ban_syokika()
color[0] = BLACK
color[1] = WHITE
turn = 0
proc = 1
elif (mx == 5 or mx == 6) and my == 5: # 後手(白)の領域をクリック
ban_syokika()
color[0] = WHITE
color[1] = BLACK
turn = 1
proc = 1
else:
msg = "選択肢をクリックしてください。" # 選択肢以外をクリックした場合
else:
msg = "選択肢をクリックしてください。" # ボードエリア外をクリックした場合
elif proc == 1: # どちらの番か表示
if turn == 0:
msg = "うんじゅぬ番どぅ"
print(f"--- ターン: {who[turn]} ({'黒' if color[turn] == BLACK else '白'}) ---")
else:
msg = "コンピュータ 考え中."
print(f"--- ターン: {who[turn]} ({'黒' if color[turn] == BLACK else '白'}) ---")
proc = 2
elif proc == 2: # 石を打つマスを決める
if turn == 0: # プレイヤー
if mc == 1:
mc = 0
# kaeseru関数に渡す前に、mx, myが有効な範囲内か再度チェック
if mx >= 0 and mx <= 7 and my >= 0 and my <= 7 and kaeseru(mx, my, color[turn], board) > 0:
ishi_utsu(mx, my, color[turn], board)
current_black_count, current_white_count = ishino_kazu(board)
space = 64 - (current_black_count + current_white_count)
print(f"うんじゅ: ({mx}, {my}) に石を置きました。")
print_board_to_console(board, "うんじゅぬ手番後")
proc = 3
else:
msg = "うまんかい置からん"
else: # コンピュータ
cx, cy = computer_strongest(color[turn])
if cx is not None and cy is not None:
ishi_utsu(cx, cy, color[turn], board)
current_black_count, current_white_count = ishino_kazu(board)
space = 64 - (current_black_count + current_white_count)
print(f"コンピュータ: ({cx}, {cy}) に石を置きました。")
print_board_to_console(board, "コンピュータの手番後")
proc = 3
elif proc == 3: # 打つ番を交代
msg = ""
turn = 1 - turn
proc = 4
elif proc == 4: # 打てるマスがあるか確認
if space == 0:
print("\n盤面が全て埋まりました。ゲーム終了です。")
proc = 5
elif not uteru_masu(BLACK, board) and not uteru_masu(WHITE, board):
print("\nどちらのプレイヤーも打てるマスがないため、ゲーム終了です。")
tkinter.messagebox.showinfo("", "どちらも打てないので終了です")
proc = 5
elif not uteru_masu(color[turn], board):
print(f"\n{who[turn]} は打てるマスがないため、パスします。")
tkinter.messagebox.showinfo("", who[turn] + "は打てないのでパスです")
proc = 3
else:
proc = 1
elif proc == 5: # 勝敗判定
b, w = ishino_kazu(board)
print(f"\n--- ゲーム終了 ---")
print(f"最終結果: 黒={b}、白={w}")
tkinter.messagebox.showinfo("終了", "黒={}、白={}".format(b, w))
if (color[0] == BLACK and b > w) or (color[0] == WHITE and w > b):
print("うんじゅの勝ち!")
tkinter.messagebox.showinfo("", "うんじゅぬ勝ち!")
elif (color[1] == BLACK and b > w) or (color[1] == WHITE and w > b):
print("コンピュータの勝ち!")
tkinter.messagebox.showinfo("", "コンピュータの勝ち!")
else:
print("引き分け")
tkinter.messagebox.showinfo("", "引き分け")
proc = 0
root.after(100, main)
root = tkinter.Tk()
root.title("ひっくりけぇ~さぁ~")
root.resizable(True, True) # ウィンドウのリサイズを許可
cvs = tkinter.Canvas(width=640, height=700, bg="green") # 初期サイズ
cvs.pack(fill="both", expand=True) # Canvasをウィンドウサイズに合わせて拡大縮小させる
# Canvasのサイズ変更イベントをバインド
cvs.bind('<Configure>', _on_canvas_configure)
# ルートウィンドウにクリックイベントをバインド(Canvas内をクリックしても反応するように)
root.bind("<Button>", click)
# Initial call to main function.
# _on_canvas_configure will be called automatically by Tkinter once the window is displayed and resized.
root.after(100, main)
root.mainloop()