0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【python】であっち向いてホイ

Last updated at Posted at 2022-07-22

じゃんけんゲームの作り方を見て同じような方法であっち向いてホイもできるのではないかと思い
下記のサイトを参考に作りました。
この後は連勝数の表示や勝った時だけ音が鳴るようにしたいと考えています。

環境

OS Windows10
言語 Python3.8.3
IDE visual studio code
from cProfile import label
from email.mime import base
import tkinter as tk
import random


def btn_click():
    num = random.randint(0,3)
    
    def return_screen():
        baseGround_new_screen.destroy()
    
    baseGround_new_screen = tk.Tk()

    baseGround_new_screen.geometry("300x300")

    baseGround_new_screen.title("結果")

    if i == num:
        label_filename = tk.Label(baseGround_new_screen, text = "あなたの勝ちです。")
    
    elif i != num:
        label_filename = tk.Label(baseGround_new_screen, text = "あなたの負けです。")
    
    label_filename.pack()

    #ボタン処理
    btn_return = tk.Button(baseGround_new_screen, text = "前の画面に戻る", command = return_screen)
    btn_return.pack()
    baseGround_new_screen.mainloop()

baseGround = tk.Tk()

baseGround.geometry("300x300")
baseGround.title("あっち向いてホイ")

label_1 = tk.Label(baseGround, text = "あっち向いてホイをします。")
label_1.pack()

label_2 = tk.Label(baseGround, text = "上下左右のどれかを選択してください。")
label_2.pack()

btn = tk.Button(baseGround, text = "OK", command = btn_click)
btn.place(x = 120, y = 140)

# ラジオボタンに表示する文字
item = ["↑上", "↓下", "←左", "→右"]

# Intavarオブジェクトを作成して変数に代入
val = tk.IntVar()

for i in range(len(item)):
    tk.Radiobutton(baseGround, value = i, variable = val, text = item[i]).pack()

baseGround.mainloop()

0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?