2019年6月13日木曜日

円が大きくなるプログラム

円が大きくなるプログラムです。



#coding:utf-8

import tkinter as tk

a = 10

def move():
    global a
    canvas.create_oval(300 - a, 200 - a, 300 + a, 200 + a, fill='red', width=0)
    a += 1
    root.after(20, move)

root = tk.Tk()
root.geometry('600x400')
root.title('円が大きくなるプログラム')

canvas = tk.Canvas(root, width = 600, height = 400, bg = 'white')

canvas.place(x = 0, y = 0)

root.after(10, move)

root.mainloop()


メモ

・真ん中から赤い円が広がってくるように見えるようにしました。

円が右に移動していくように見えるプログラム

円が右に移動していくように見えるプログラムです。




#coding:utf-8

import tkinter as tk

x = 0
y = 200

def move():
    global x , y
    canvas.create_oval(x - 20, y - 20, x + 20, y + 20, fill='white', width=0)
    x += 1
    canvas.create_oval(x - 20, y - 20, x + 20, y + 20, fill='red', width=0)
    root.after(20, move)

root = tk.Tk()
root.geometry('600x400')
root.title('円が右に移動していくプログラム')

canvas = tk.Canvas(root, width = 600, height = 400, bg = 'white')

canvas.place(x = 0, y = 0)

root.after(10, move)

root.mainloop()

メモ

・「いちばんやさしいPython入門教室」という本を参考にしています。

2019年5月31日金曜日

クリックしたところに円と四角が描かれるプログラム その5

クリックしたところに円と四角が描かれるプログラム その5です。



#coding:utf-8

import tkinter as tk


def click(event):
    if editbox1.get() == '':
        pass
    else:
        set_size = int(editbox1.get())
        canvas.create_oval(event.x - set_size, event.y - set_size, event.x + set_size, event.y + set_size, fill = set_color, width = 0)

def click2(event):
    if editbox1.get() == '':
        pass
    else:
        set_size = int(editbox1.get())
        canvas.create_rectangle(event.x - set_size, event.y - set_size, event.x + set_size, event.y + set_size, fill = set_color, width = 0)

def reset():
    canvas.create_rectangle(0, 0, 600, 400, fill = 'white', width = 0)

def blue():
    global set_color
    set_color = 'blue'

def red():
    global set_color
    set_color = 'red'

def green():
    global set_color
    set_color = 'green'

def white():
    global set_color
    set_color = 'white'

def yellow():
    global set_color
    set_color = 'yellow'

def black():
    global set_color
    set_color = 'black'

root = tk.Tk()
root.geometry('900x400')
root.title('クリックすると円と四角が描かれる')

button1 = tk.Button(root,text = 'リセット', font = ('Courier',14),command = reset)
b_blue = tk.Button(root,text = ' 青 ', font = ('Courier',14),command = blue)
b_red = tk.Button(root,text = ' 赤 ', font = ('Courier',14),command = red)
b_green = tk.Button(root,text = ' 緑 ', font = ('Courier',14),command = green)
b_white = tk.Button(root,text = ' 白 ', font = ('Courier',14),command = white)
b_yellow = tk.Button(root,text = ' 黄 ', font = ('Courier',14),command = yellow)
b_black = tk.Button(root,text = ' 黒 ', font = ('Courier',14),command = black)
label1 = tk.Label(root,text = 'サイズを入力', font = ('Courier',14))
editbox1 = tk.Entry(width = 4, font = ('Courier',14))

canvas = tk.Canvas(root, width = 600, height = 400, bg = 'white')

button1.place(x = 700, y = 350)
b_blue.place(x = 620, y = 20)
b_red.place(x = 710, y = 20)
b_green.place(x = 800, y = 20)
b_white.place(x = 620, y = 70)
b_yellow.place(x = 710, y = 70)
b_black.place(x = 800, y = 70)
label1.place(x = 620, y = 120)
editbox1.place(x = 650, y = 150)

canvas.place(x = 0, y = 0)

set_color = 'red'

canvas.bind('<Button-1>', click)
canvas.bind('<Button-3>', click2)

root.mainloop()


メモ

・丸や四角のサイズを変更できるようにしました。
・サイズを入力していない間は、何も描かれないようにしました。

2019年5月30日木曜日

クリックしたところに円と四角が描かれるプログラム その4

クリックしたところに円と四角が描かれるプログラム その4です。



#coding:utf-8

import tkinter as tk


def click(event):
    canvas.create_oval(event.x - 20, event.y -20, event.x +20, event.y +20, fill = set_color, width = 0)

def click2(event):
    canvas.create_rectangle(event.x - 20, event.y -20, event.x +20, event.y +20, fill = set_color, width = 0)

def reset():
    canvas.create_rectangle(0, 0, 600, 400, fill = 'white', width = 0)

def blue():
    global set_color
    set_color = 'blue'

def red():
    global set_color
    set_color = 'red'

def green():
    global set_color
    set_color = 'green'

def white():
    global set_color
    set_color = 'white'

def yellow():
    global set_color
    set_color = 'yellow'

def black():
    global set_color
    set_color = 'black'

root = tk.Tk()
root.geometry('900x400')
root.title('クリックすると円と四角が描かれる')

button1 = tk.Button(root,text = 'リセット', font = ('Courier',14),command = reset)
b_blue = tk.Button(root,text = ' 青 ', font = ('Courier',14),command = blue)
b_red = tk.Button(root,text = ' 赤 ', font = ('Courier',14),command = red)
b_green = tk.Button(root,text = ' 緑 ', font = ('Courier',14),command = green)
b_white = tk.Button(root,text = ' 白 ', font = ('Courier',14),command = white)
b_yellow = tk.Button(root,text = ' 黄 ', font = ('Courier',14),command = yellow)
b_black = tk.Button(root,text = ' 黒 ', font = ('Courier',14),command = black)
canvas = tk.Canvas(root, width = 600, height = 400, bg = 'white')

button1.place(x = 700, y = 350)
b_blue.place(x = 620, y = 20)
b_red.place(x = 710, y = 20)
b_green.place(x = 800, y = 20)
b_white.place(x = 620, y = 70)
b_yellow.place(x = 710, y = 70)
b_black.place(x = 800, y = 70)
canvas.place(x = 0, y = 0)

set_color = 'red'

canvas.bind('<Button-1>', click)
canvas.bind('<Button-3>', click2)

root.mainloop()


メモ

・色を選択できるようにしました。

クリックしたところに円と四角が描かれるプログラム その3

クリックしたところに円と四角が描かれるプログラム その3です。



#coding:utf-8


import tkinter as tk

def click(event):
    canvas.create_oval(event.x - 20, event.y -20, event.x +20, event.y +20, fill = 'red', width = 0)

def click2(event):
    canvas.create_rectangle(event.x - 20, event.y -20, event.x +20, event.y +20, fill = 'blue', width = 0)

def reset():
    canvas.create_rectangle(0, 0, 600, 400, fill = 'white', width = 0)

root = tk.Tk()
root.geometry('900x400')
root.title('クリックすると円と四角が描かれる')

button1 = tk.Button(root,text = 'リセット', font = ('Courier',14),command = reset)
canvas = tk.Canvas(root, width = 600, height = 400, bg = 'white')

button1.place(x = 700, y = 350)
canvas.place(x = 0, y = 0)

canvas.bind('<Button-1>', click)
canvas.bind('<Button-3>', click2)

root.mainloop()


メモ

・リセットボダンを作りました。

2019年5月29日水曜日

クリックしたところに円と四角が描かれるプログラム その2

クリックしたところに円と四角が描かれるプログラム その2です。



#coding:utf-8


import tkinter as tk

def click(event):
    canvas.create_oval(event.x - 20, event.y -20, event.x +20, event.y +20, fill = 'red', width = 0)

def click2(event):
    canvas.create_rectangle(event.x - 20, event.y -20, event.x +20, event.y +20, fill = 'blue', width = 0)

def click3(event):
    canvas.create_rectangle(0, 0, 600, 400, fill = 'white', width = 0)

root = tk.Tk()
root.geometry('600x400')
root.title('クリックすると円と四角が描かれる')

canvas = tk.Canvas(root, width = 600, height = 400, bg = 'white')
canvas.place(x = 0, y = 0)

canvas.bind('<Button-1>', click)
canvas.bind('<Button-2>', click3)
canvas.bind('<Button-3>', click2)

root.mainloop()


メモ

・「いちばんやさしいPython入門教室」という本を参考にしています。
・マウスの中央ボタンを押すと白紙になるようにしました。

クリックしたところに円と四角が描かれるプログラム

クリックしたところに円と四角が描かれるプログラムです。



#coding:utf-8


import tkinter as tk

def click(event):
    canvas.create_oval(event.x - 20, event.y -20, event.x +20, event.y +20, fill = 'red', width = 0)

def click2(event):
    canvas.create_rectangle(event.x - 20, event.y -20, event.x +20, event.y +20, fill = 'blue', width = 0)

root = tk.Tk()
root.geometry('600x400')
root.title('クリックすると円と四角が描かれる')

canvas = tk.Canvas(root, width = 600, height = 400, bg = 'white')
canvas.place(x = 0, y = 0)

canvas.bind('<Button-1>', click)
canvas.bind('<Button-3>', click2)

root.mainloop()


メモ

・「いちばんやさしいPython入門教室」という本を参考にしています。
・右クリックすると四角が描かれるように追加しました。

クリックしたところに円が描かれるプログラム

クリックしたところに円が描かれるプログラムです。



#coding:utf-8


import tkinter as tk

def click(event):
    canvas.create_oval(event.x - 20, event.y -20, event.x +20, event.y +20, fill = 'red', width = 0)

root = tk.Tk()
root.geometry('600x400')
root.title('クリックすると円が描かれる')

canvas = tk.Canvas(root, width = 600, height = 400, bg = 'white')
canvas.place(x = 0, y = 0)

canvas.bind('<Button-1>', click)

root.mainloop()


メモ

・「いちばんやさしいPython入門教室」という本を参考にしています。

2019年5月28日火曜日

日本の国旗を描くプログラム

日本の国旗を描くプログラムです。




#coding:utf-8


import tkinter as tk

root = tk.Tk()
root.geometry('600x400')
root.title('日本の国旗を描く')



canvas = tk.Canvas(root,width = 600 ,height = 400 ,bg = '#66cdaa')
canvas.place(x = 0 ,y = 0)

canvas.create_rectangle(300 - 70 , 200 - 50 , 300 + 70 , 200 + 50 , width = 2 , fill = 'white')
canvas.create_oval(300 - 20 , 200 - 20 , 300 + 20 , 200 + 20 , fill = 'red' , width = 0)


root.mainloop()


メモ

・四角と丸で描けるのはこれくらいしか思いつかなかった。

円を描くプログラム その2

円を描くプログラム その2です。




#coding:utf-8


import tkinter as tk

root = tk.Tk()
root.geometry('600x400')
root.title('円を描く')



canvas = tk.Canvas(root,width = 600 ,height = 400 ,bg = '#66cdaa')
canvas.place(x = 0 ,y = 0)

canvas.create_oval(300 - 50 , 200 - 50 , 300 + 50 , 200 + 50 , width = 10)
canvas.create_oval(300 - 20 , 200 - 20 , 300 + 20 , 200 + 20 , outline = 'blue' , width = 3)
canvas.create_oval(300 - 15 , 200 - 15 , 300 + 15 , 200 + 15 , outline = '#ffffff')
canvas.create_oval(300 - 10 , 200 - 10 , 300 + 10 , 200 + 10 , fill = 'red')
canvas.create_oval(300 - 5 , 200 - 5 , 300 + 5 , 200 + 5 , fill = 'white')



root.mainloop()
 

メモ

・「いちばんやさしいPython入門教室」という本を参考にしています。
・色をつけたり・線の太さを変えたりしています。

2019年5月24日金曜日

円を描くプログラム

円を描くプログラムです。




#coding:utf-8


import tkinter as tk

root = tk.Tk()
root.geometry('600x400')
root.title('円を描く')



canvas = tk.Canvas(root,width = 600 ,height = 400 ,bg = '#66cdaa')
canvas.place(x = 0 ,y = 0)

canvas.create_oval(300 - 50 , 200 - 50 , 300 + 50 , 200 + 50)
canvas.create_oval(300 - 20 , 200 - 20 , 300 + 20 , 200 + 20)
canvas.create_oval(300 - 15 , 200 - 15 , 300 + 15 , 200 + 15)
canvas.create_oval(300 - 10 , 200 - 10 , 300 + 10 , 200 + 10)
canvas.create_oval(300 - 5 , 200 - 5 , 300 + 5 , 200 + 5)



root.mainloop()
 

メモ

・「いちばんやさしいPython入門教室」という本を参考にしています。

2019年5月22日水曜日

じゃんけんゲーム(ゲーム画面あり)のプログラム その9

じゃんけんゲーム(ゲーム画面あり)のプログラム その9です。




#coding:utf-8

import tkinter as tk
import random



def click0():
    if editbox1.get() == '':
        rirekibox.insert('1.0','名前を入力して下さい' + '\n')
    else:
        rirekibox.insert('1.0',print_hand(0,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert('2.0',print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(0, computer_hand)
        rirekibox.insert('3.0','結果は' + result + 'でした' + '\n')
        rirekibox.insert('4.0','-'*30 + '\n')
def click1():
    if editbox1.get() == '':
        rirekibox.insert('1.0','名前を入力して下さい' + '\n')
    else:
        rirekibox.insert('1.0',print_hand(1,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert('2.0',print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(1, computer_hand)
        rirekibox.insert('3.0','結果は' + result + 'でした' + '\n')
        rirekibox.insert('4.0','-'*30 + '\n')
def click2():
    if editbox1.get() == '':
        rirekibox.insert('1.0','名前を入力して下さい' + '\n')
    else:
        rirekibox.insert('1.0',print_hand(2,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert('2.0',print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(2, computer_hand)
        rirekibox.insert('3.0','結果は' + result + 'でした' + '\n')
        rirekibox.insert('4.0','-'*30 + '\n')

def click3():
    rirekibox.delete('1.0','end')
    

def print_hand(hand, name):
    hands = ['グー', 'チョキ', 'パー']
    return name + 'は' + hands[hand] + 'を出しました'

def judge(player, computer):
    if player == computer:
        return '引き分け'
    elif player == 0 and computer == 1:
        return '勝ち'
    elif player == 1 and computer == 2:
        return '勝ち'
    elif player == 2 and computer == 0:
        return '勝ち'
    else:
        return '負け'
    

root = tk.Tk()
root.geometry('800x380')
root.title('じゃんけんゲーム')

label1 = tk.Label(root,text = 'じゃんけんをはじめます。', font = ('Courier',14))
label2 = tk.Label(root,text = '名前を入力して下さい。', font = ('Courier',14))
editbox1 = tk.Entry(width = 15, font = ('Courier',14))
label3 =tk.Label(root,text = '何を出しますか?', font = ('Courier',14))
button0 = tk.Button(root,text = ' グー  ', font = ('Courier',14),command = click0)
button1 = tk.Button(root,text = ' チョキ ', font = ('Courier',14),command = click1)
button2 = tk.Button(root,text = ' パー  ', font = ('Courier',14),command = click2)
button3 = tk.Button(root,text = '結果削除', font = ('Courier',14),command = click3)
rirekibox = tk.Text(root, font = ('Courier',10))

label1.place(x = 20, y = 20)
label2.place(x = 20, y = 50)
editbox1.place(x = 40, y = 90)
label3.place(x = 20, y = 150)
button0.place(x = 20, y = 190)
button1.place(x = 150, y = 190)
button2.place(x = 280, y = 190)
button3.place(x = 320, y = 300)
rirekibox.place(x = 500, y =0, width = 300, height = 380)




root.mainloop()


メモ

・「---------------」の表示を「'-'*30」のように書き換えました。繰り返しの時はこのほうがスッキリするようですね。

じゃんけんゲーム(ゲーム画面あり)のプログラム その8

じゃんけんゲーム(ゲーム画面あり)のプログラム その8です。




#coding:utf-8

import tkinter as tk
import random


def click0():
    if editbox1.get() == '':
        rirekibox.insert('1.0','名前を入力して下さい' + '\n')
    else:
        rirekibox.insert('1.0',print_hand(0,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert('2.0',print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(0, computer_hand)
        rirekibox.insert('3.0','結果は' + result + 'でした' + '\n')
        rirekibox.insert('4.0','---------------------------' + '\n')
def click1():
    if editbox1.get() == '':
        rirekibox.insert('1.0','名前を入力して下さい' + '\n')
    else:
        rirekibox.insert('1.0',print_hand(1,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert('2.0',print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(1, computer_hand)
        rirekibox.insert('3.0','結果は' + result + 'でした' + '\n')
        rirekibox.insert('4.0','---------------------------' + '\n')
def click2():
    if editbox1.get() == '':
        rirekibox.insert('1.0','名前を入力して下さい' + '\n')
    else:
        rirekibox.insert('1.0',print_hand(2,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert('2.0',print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(2, computer_hand)
        rirekibox.insert('3.0','結果は' + result + 'でした' + '\n')
        rirekibox.insert('4.0','---------------------------' + '\n')

def click3():
    rirekibox.delete('1.0','end')
    

def print_hand(hand, name):
    hands = ['グー', 'チョキ', 'パー']
    return name + 'は' + hands[hand] + 'を出しました'

def judge(player, computer):
    if player == computer:
        return '引き分け'
    elif player == 0 and computer == 1:
        return '勝ち'
    elif player == 1 and computer == 2:
        return '勝ち'
    elif player == 2 and computer == 0:
        return '勝ち'
    else:
        return '負け'
    

root = tk.Tk()
root.geometry('800x380')
root.title('じゃんけんゲーム')

label1 = tk.Label(root,text = 'じゃんけんをはじめます。', font = ('Courier',14))
label2 = tk.Label(root,text = '名前を入力して下さい。', font = ('Courier',14))
editbox1 = tk.Entry(width = 15, font = ('Courier',14))
label3 =tk.Label(root,text = '何を出しますか?', font = ('Courier',14))
button0 = tk.Button(root,text = ' グー  ', font = ('Courier',14),command = click0)
button1 = tk.Button(root,text = ' チョキ ', font = ('Courier',14),command = click1)
button2 = tk.Button(root,text = ' パー  ', font = ('Courier',14),command = click2)
button3 = tk.Button(root,text = '結果削除', font = ('Courier',14),command = click3)
rirekibox = tk.Text(root, font = ('Courier',10))

label1.place(x = 20, y = 20)
label2.place(x = 20, y = 50)
editbox1.place(x = 40, y = 90)
label3.place(x = 20, y = 150)
button0.place(x = 20, y = 190)
button1.place(x = 150, y = 190)
button2.place(x = 280, y = 190)
button3.place(x = 320, y = 300)
rirekibox.place(x = 500, y =0, width = 300, height = 380)




root.mainloop()


メモ

・右側の結果表示の仕方を変えました。下に追加していくと見えなくなるので上に追加されるように変更。

2019年5月21日火曜日

じゃんけんゲームのゲーム画面のプログラム その7

じゃんけんゲームのゲーム画面のプログラム その7です。




#coding:utf-8

import tkinter as tk
import random


def click0():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,print_hand(0,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert(tk.END,print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(0, computer_hand)
        rirekibox.insert(tk.END,'結果は' + result + 'でした' + '\n')
        rirekibox.insert(tk.END,'---------------------------' + '\n')
def click1():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,print_hand(1,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert(tk.END,print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(1, computer_hand)
        rirekibox.insert(tk.END,'結果は' + result + 'でした' + '\n')
        rirekibox.insert(tk.END,'---------------------------' + '\n')
def click2():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,print_hand(2,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert(tk.END,print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(2, computer_hand)
        rirekibox.insert(tk.END,'結果は' + result + 'でした' + '\n')
        rirekibox.insert(tk.END,'---------------------------' + '\n')

def click3():
    rirekibox.delete('1.0','end')
    

def print_hand(hand, name):
    hands = ['グー', 'チョキ', 'パー']
    return name + 'は' + hands[hand] + 'を出しました'

def judge(player, computer):
    if player == computer:
        return '引き分け'
    elif player == 0 and computer == 1:
        return '勝ち'
    elif player == 1 and computer == 2:
        return '勝ち'
    elif player == 2 and computer == 0:
        return '勝ち'
    else:
        return '負け'
    

root = tk.Tk()
root.geometry('800x380')
root.title('じゃんけんゲーム')

label1 = tk.Label(root,text = 'じゃんけんをはじめます。', font = ('Courier',14))
label2 = tk.Label(root,text = '名前を入力して下さい。', font = ('Courier',14))
editbox1 = tk.Entry(width = 15, font = ('Courier',14))
label3 =tk.Label(root,text = '何を出しますか?', font = ('Courier',14))
button0 = tk.Button(root,text = ' グー  ', font = ('Courier',14),command = click0)
button1 = tk.Button(root,text = ' チョキ ', font = ('Courier',14),command = click1)
button2 = tk.Button(root,text = ' パー  ', font = ('Courier',14),command = click2)
button3 = tk.Button(root,text = '結果削除', font = ('Courier',14),command = click3)
rirekibox = tk.Text(root, font = ('Courier',10))

label1.place(x = 20, y = 20)
label2.place(x = 20, y = 50)
editbox1.place(x = 40, y = 90)
label3.place(x = 20, y = 150)
button0.place(x = 20, y = 190)
button1.place(x = 150, y = 190)
button2.place(x = 280, y = 190)
button3.place(x = 320, y = 300)
rirekibox.place(x = 500, y =0, width = 300, height = 380)




root.mainloop()


メモ

・ゲームが出来るようになりました。
・「結果削除」ボタンに変更して、右側に表示していた履歴を消すようにしました。

2019年5月20日月曜日

じゃんけんゲームのゲーム画面のプログラム その6

1から100までの数字を2の倍数、3の倍数、6の倍数かを調べるプログラムです。



#coding:utf-8

import tkinter as tk
import random


def click0():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,print_hand(0,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert(tk.END,print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(0, computer_hand)
        rirekibox.insert(tk.END,'結果は' + result + 'でした' + '\n')
        rirekibox.insert(tk.END,'---------------------------' + '\n')
def click1():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,print_hand(1,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert(tk.END,print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(1, computer_hand)
        rirekibox.insert(tk.END,'結果は' + result + 'でした' + '\n')
        rirekibox.insert(tk.END,'---------------------------' + '\n')
def click2():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,print_hand(2,editbox1.get()) + '\n')
        computer_hand = random.randint(0,2)
        rirekibox.insert(tk.END,print_hand(computer_hand,'コンピューター') + '\n')
        result = judge(2, computer_hand)
        rirekibox.insert(tk.END,'結果は' + result + 'でした' + '\n')
        rirekibox.insert(tk.END,'---------------------------' + '\n')


def print_hand(hand, name):
    hands = ['グー', 'チョキ', 'パー']
    return name + 'は' + hands[hand] + 'を出しました'

def judge(player, computer):
    if player == computer:
        return '引き分け'
    elif player == 0 and computer == 1:
        return '勝ち'
    elif player == 1 and computer == 2:
        return '勝ち'
    elif player == 2 and computer == 0:
        return '勝ち'
    else:
        return '負け'
    

root = tk.Tk()
root.geometry('800x380')
root.title('じゃんけんゲーム')

label1 = tk.Label(root,text = 'じゃんけんをはじめます。', font = ('Courier',14))
label2 = tk.Label(root,text = '名前を入力して下さい。', font = ('Courier',14))
editbox1 = tk.Entry(width = 15, font = ('Courier',14))
label3 =tk.Label(root,text = '何を出しますか?', font = ('Courier',14))
button0 = tk.Button(root,text = ' グー  ', font = ('Courier',14),command = click0)
button1 = tk.Button(root,text = ' チョキ ', font = ('Courier',14),command = click1)
button2 = tk.Button(root,text = ' パー  ', font = ('Courier',14),command = click2)
button3 = tk.Button(root,text = 'ゲーム終了', font = ('Courier',14))
rirekibox = tk.Text(root, font = ('Courier',10))

label1.place(x = 20, y = 20)
label2.place(x = 20, y = 50)
editbox1.place(x = 40, y = 90)
label3.place(x = 20, y = 150)
button0.place(x = 20, y = 190)
button1.place(x = 150, y = 190)
button2.place(x = 280, y = 190)
button3.place(x = 320, y = 300)
rirekibox.place(x = 500, y =0, width = 300, height = 380)




root.mainloop()
 

メモ

・ゲームが出来るようになりました。
・コンピューターの手と結果が表示されるようになりました。

じゃんけんゲームのゲーム画面のプログラム その5

じゃんけんゲームのゲーム画面のプログラム その5です。




#coding:utf-8

import tkinter as tk

def click1():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,print_hand(0,editbox1.get()) + '\n')
def click2():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,print_hand(1,editbox1.get()) + '\n')
def click3():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,print_hand(2,editbox1.get()) + '\n')


def print_hand(hand, name):
    hands = ['グー', 'チョキ', 'パー']
    return name + 'は' + hands[hand] + 'を出しました'


root = tk.Tk()
root.geometry('800x380')
root.title('じゃんけんゲーム')

label1 = tk.Label(root,text = 'じゃんけんをはじめます。', font = ('Courier',14))
label2 = tk.Label(root,text = '名前を入力して下さい。', font = ('Courier',14))
editbox1 = tk.Entry(width = 15, font = ('Courier',14))
label3 =tk.Label(root,text = '何を出しますか?', font = ('Courier',14))
button1 = tk.Button(root,text = ' グー  ', font = ('Courier',14),command = click1)
button2 = tk.Button(root,text = ' チョキ ', font = ('Courier',14),command = click2)
button3 = tk.Button(root,text = ' パー  ', font = ('Courier',14),command = click3)
button4 = tk.Button(root,text = 'ゲーム終了', font = ('Courier',14))
rirekibox = tk.Text(root, font = ('Courier',14))

label1.place(x = 20, y = 20)
label2.place(x = 20, y = 50)
editbox1.place(x = 40, y = 90)
label3.place(x = 20, y = 150)
button1.place(x = 20, y = 190)
button2.place(x = 150, y = 190)
button3.place(x = 280, y = 190)
button4.place(x = 320, y = 300)
rirekibox.place(x = 500, y =0, width = 300, height = 380)




root.mainloop()


メモ
・まだゲームは出来ません。
・画面表示をこんな感じにしたいなと思っています。
・「いちばんやさしいPython入門教室」という本を参考にしています。
・前回と表示はほとんど変わらないが、プレイヤーが何を出したのかを関数で処理するようにしています。

2019年5月18日土曜日

じゃんけんゲームのゲーム画面のプログラム その4

じゃんけんゲームのゲーム画面のプログラム その4です。




#coding:utf-8

import tkinter as tk

def click1():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,editbox1.get() + 'は、グーを出しました' + '\n')
def click2():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:    
        rirekibox.insert(tk.END,editbox1.get() + 'は、チョキを出しました'+'\n')
def click3():
    if editbox1.get() == '':
        rirekibox.insert(tk.END,'名前を入力して下さい' + '\n')
    else:
        rirekibox.insert(tk.END,editbox1.get() + 'は、パーを出しました'+'\n')


        



root = tk.Tk()
root.geometry('800x380')
root.title('じゃんけんゲーム')

label1 = tk.Label(root,text = 'じゃんけんをはじめます。', font = ('Courier',14))
label2 = tk.Label(root,text = '名前を入力して下さい。', font = ('Courier',14))
editbox1 = tk.Entry(width = 15, font = ('Courier',14))
label3 =tk.Label(root,text = '何を出しますか?', font = ('Courier',14))
button1 = tk.Button(root,text = ' グー  ', font = ('Courier',14),command = click1)
button2 = tk.Button(root,text = ' チョキ ', font = ('Courier',14),command = click2)
button3 = tk.Button(root,text = ' パー  ', font = ('Courier',14),command = click3)
button4 = tk.Button(root,text = 'ゲーム終了', font = ('Courier',14))
rirekibox = tk.Text(root, font = ('Courier',14))

label1.place(x = 20, y = 20)
label2.place(x = 20, y = 50)
editbox1.place(x = 40, y = 90)
label3.place(x = 20, y = 150)
button1.place(x = 20, y = 190)
button2.place(x = 150, y = 190)
button3.place(x = 280, y = 190)
button4.place(x = 320, y = 300)
rirekibox.place(x = 500, y =0, width = 300, height = 380)




root.mainloop()


メモ

・まだゲームは出来ません。
・画面表示をこんな感じにしたいなと思っています。
・「いちばんやさしいPython入門教室」という本を参考にしています。
・プレイヤーの名前を入力していない場合は「名前を入力して下さい」と表示されるようにした。

じゃんけんゲームのゲーム画面のプログラム その3

じゃんけんゲームのゲーム画面のプログラム その3です。




#coding:utf-8

import tkinter as tk

def click1():
    rirekibox.insert(tk.END,editbox1.get() + 'は、グーを出しました' + '\n')
def click2():
    rirekibox.insert(tk.END,editbox1.get() + 'は、チョキを出しました'+'\n')
def click3():
    rirekibox.insert(tk.END,editbox1.get() + 'は、パーを出しました'+'\n')


root = tk.Tk()
root.geometry('800x380')
root.title('じゃんけんゲーム')

label1 = tk.Label(root,text = 'じゃんけんをはじめます。', font = ('Courier',14))
label2 = tk.Label(root,text = '名前を入力して下さい。', font = ('Courier',14))
editbox1 = tk.Entry(width = 15, font = ('Courier',14))
label3 =tk.Label(root,text = '何を出しますか?', font = ('Courier',14))
button1 = tk.Button(root,text = ' グー  ', font = ('Courier',14),command = click1)
button2 = tk.Button(root,text = ' チョキ ', font = ('Courier',14),command = click2)
button3 = tk.Button(root,text = ' パー  ', font = ('Courier',14),command = click3)
button4 = tk.Button(root,text = 'ゲーム終了', font = ('Courier',14))
rirekibox = tk.Text(root, font = ('Courier',14))

label1.place(x = 20, y = 20)
label2.place(x = 20, y = 50)
editbox1.place(x = 40, y = 90)
label3.place(x = 20, y = 150)
button1.place(x = 20, y = 190)
button2.place(x = 150, y = 190)
button3.place(x = 280, y = 190)
button4.place(x = 320, y = 300)
rirekibox.place(x = 500, y =0, width = 300, height = 380)




root.mainloop()
  

メモ

・まだゲームは出来ません。
・画面表示をこんな感じにしたいなと思っています。
・「いちばんやさしいPython入門教室」という本を参考にしています。
・プレイヤーの名前を入力してそれが表示されるようにしました。

2019年5月17日金曜日

じゃんけんゲームのゲーム画面のプログラム その2

じゃんけんゲームのゲーム画面のプログラム その2です。



#coding:utf-8

import tkinter as tk

def click1():
    rirekibox.insert(tk.END,'グーを出しました'+'\n')
def click2():
    rirekibox.insert(tk.END,'チョキを出しました'+'\n')
def click3():
    rirekibox.insert(tk.END,'パーを出しました'+'\n')
    

root = tk.Tk()
root.geometry('800x380')
root.title('じゃんけんゲーム')

label1 = tk.Label(root,text = 'じゃんけんをはじめます。', font = ('Courier',14))
label2 = tk.Label(root,text = '名前を入力して下さい。', font = ('Courier',14))
editbox1 = tk.Entry(width = 15, font = ('Courier',14))
label3 =tk.Label(root,text = '何を出しますか?', font = ('Courier',14))
button1 = tk.Button(root,text = ' グー  ', font = ('Courier',14),command = click1)
button2 = tk.Button(root,text = ' チョキ ', font = ('Courier',14),command = click2)
button3 = tk.Button(root,text = ' パー  ', font = ('Courier',14),command = click3)
button4 = tk.Button(root,text = 'ゲーム終了', font = ('Courier',14))
rirekibox = tk.Text(root, font = ('Courier',14))

label1.place(x = 20, y = 20)
label2.place(x = 20, y = 50)
editbox1.place(x = 40, y = 90)
label3.place(x = 20, y = 150)
button1.place(x = 20, y = 190)
button2.place(x = 150, y = 190)
button3.place(x = 280, y = 190)
button4.place(x = 320, y = 300)
rirekibox.place(x = 500, y =0, width = 300, height = 380)




root.mainloop()


メモ

・まだゲームは出来ません。
・画面表示をこんな感じにしたいなと思っています。
・「いちばんやさしいPython入門教室」という本を参考にしています。
・右側に履歴表示されるようにしました。
・ボタンを押すと文字が表示されるようにしました。

2019年5月16日木曜日

じゃんけんゲームのゲーム画面のプログラム

じゃんけんゲームのゲーム画面のプログラムです。



#coding:utf-8

import tkinter as tk

root = tk.Tk()
root.geometry('500x380')
root.title('じゃんけんゲーム')

label1 = tk.Label(root,text = 'じゃんけんをはじめます。', font = ('Courier',14))
label2 = tk.Label(root,text = '名前を入力して下さい。', font = ('Courier',14))
editbox1 = tk.Entry(width = 15, font = ('Courier',14))
label3 =tk.Label(root,text = '何を出しますか?', font = ('Courier',14))
button1 = tk.Button(root,text = ' グー  ', font = ('Courier',14))
button2 = tk.Button(root,text = ' チョキ ', font = ('Courier',14))
button3 = tk.Button(root,text = ' パー  ', font = ('Courier',14))
button4 = tk.Button(root,text = 'ゲーム終了', font = ('Courier',14))

label1.place(x = 20, y = 20)
label2.place(x = 20, y = 50)
editbox1.place(x = 40, y = 90)
label3.place(x = 20, y = 150)
button1.place(x = 20, y = 190)
button2.place(x = 150, y = 190)
button3.place(x = 280, y = 190)
button4.place(x = 320, y = 300)

root.mainloop()


メモ

・まだゲームは出来ません。
・画面表示をこんな感じにしたいなと思っています。
・「いちばんやさしいPython入門教室」という本を参考にしています。