update,
This commit is contained in:
41
jktjoeaj703/task1/_ref/py_original_GUI-main/Basic/button.py
Normal file
41
jktjoeaj703/task1/_ref/py_original_GUI-main/Basic/button.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import tkinter
|
||||
|
||||
# ウィンドウの作成
|
||||
root = tkinter.Tk()
|
||||
root.title("Button practice")
|
||||
root.iconbitmap('icon.ico')
|
||||
root.geometry('550×550')
|
||||
root.resizable(0, 0) #サイズの変更禁止
|
||||
root.config(bg='red') #背景色
|
||||
|
||||
# ボタンの作成
|
||||
button_1 = tkinter.Button(root, text='ボタン1')
|
||||
button_1.grid(row=0, column=0)
|
||||
|
||||
button_2 = tkinter.Button(root, text='ボタン2')
|
||||
button_2.grid(row=0, column=1)
|
||||
|
||||
button_3 = tkinter.Button(root, text='ボタン3', bg='pink', activebackground='yellow')
|
||||
button_3.grid(row=0, column=2, padx=10, pady=10, ipadx=10, ipady=10)
|
||||
|
||||
button_4 = tkinter.Button(root, text='ボタン4', borderwidth=5)
|
||||
button_4.grid(row=1, column=0, columnspan=0, sticky='WE')
|
||||
|
||||
button_5 = tkinter.Button(root, text='テスト')
|
||||
button_6 = tkinter.Button(root, text='テスト')
|
||||
button_7 = tkinter.Button(root, text='テスト')
|
||||
button_8 = tkinter.Button(root, text='テスト')
|
||||
button_9 = tkinter.Button(root, text='テスト')
|
||||
button_10 = tkinter.Button(root, text='テスト')
|
||||
|
||||
button_5.grid(row=2, column=0, padx=5, pady=5)
|
||||
button_6.grid(row=2, column=1, padx=5, pady=5)
|
||||
button_7.grid(row=2, column=2, padx=5, pady=5, sticky='w')
|
||||
button_8.grid(row=3, column=0, padx=5, pady=5)
|
||||
button_9.grid(row=3, column=1, padx=5, pady=5)
|
||||
button_10.grid(row=3, column=2, padx=5, pady=5, sticky='w')
|
||||
|
||||
|
||||
|
||||
# ウィンドウのループ処理
|
||||
root.mainloop()
|
34
jktjoeaj703/task1/_ref/py_original_GUI-main/Basic/frame.py
Normal file
34
jktjoeaj703/task1/_ref/py_original_GUI-main/Basic/frame.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import tkinter
|
||||
|
||||
# ウィンドウの作成
|
||||
root = tkinter.Tk()
|
||||
root.title("Frame practice")
|
||||
root.iconbitmap('icon.ico')
|
||||
root.geometry('550×550')
|
||||
root.resizable(0, 0) #サイズの変更禁止
|
||||
|
||||
# なぜframeを使うのか?
|
||||
# tkinter.Label(root, text='test').pack()
|
||||
# tkinter.Button(root, text='test').grid(row=0, column=0)
|
||||
|
||||
# frameの作成
|
||||
frame_1 = tkinter.Frame(root, bg='yellow')
|
||||
frame_2 = tkinter.Frame(root, bg='green')
|
||||
frame_3 = tkinter.Label(root, text='ラベルフレームです', borderwidth=5)
|
||||
|
||||
# frameをroot上に配置
|
||||
frame_1.pack(fill='both', expand=True)
|
||||
frame_2.pack(fill='both', expand=True)
|
||||
frame_3.pack(fill='both', expand=True)
|
||||
|
||||
# ウィジェットの配置
|
||||
tkinter.Label(frame_1, text='test').pack()
|
||||
tkinter.Label(frame_1, text='test').pack()
|
||||
tkinter.Label(frame_1, text='test').pack()
|
||||
|
||||
tkinter.Label(frame_2, text='test').grid(row=0, column=0)
|
||||
tkinter.Label(frame_2, text='test').grid(row=1, column=1)
|
||||
tkinter.Label(frame_2, text='test').grid(row=2, column=2)
|
||||
|
||||
# ウィンドウのループ処理
|
||||
root.mainloop()
|
37
jktjoeaj703/task1/_ref/py_original_GUI-main/Basic/label.py
Normal file
37
jktjoeaj703/task1/_ref/py_original_GUI-main/Basic/label.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import tkinter
|
||||
import tkinter.font as font
|
||||
|
||||
# ウィンドウの作成
|
||||
root = tkinter.Tk()
|
||||
root.title("Label practice!")
|
||||
root.iconbitmap('icon.ico')
|
||||
root.geometry('550×550')
|
||||
root.resizable(0, 0) #サイズの変更禁止
|
||||
root.config(bg='red') #背景色
|
||||
|
||||
# ラベルの作成
|
||||
label_1 = tkinter.Label(root, text='宜しくお願いします')
|
||||
label_1.pack()
|
||||
|
||||
label_2 = tkinter.Label(root, text='宜しくお願いします', font=('Arial',10,'bold'))
|
||||
label_2.pack()
|
||||
|
||||
label_3 = tkinter.Label(root, text='宜しくお願いします', font=('Arial',10,'bold'), bg='gray')
|
||||
label_3.pack(padx=10, pady=10)
|
||||
|
||||
label_4 = tkinter.Label(root)
|
||||
label_4.config(text='宜しくお願いします')
|
||||
label_4.config(bg='gray')
|
||||
label_4.pack(padx=10, pady=10)
|
||||
|
||||
label_5 = tkinter.Label(root, text='宜しくお願いします', font=('Arial',10,'bold'), bg='gray', fg='green')
|
||||
label_5.pack(padx=10, pady=(0, 10), ipadx=10, ipady=10, anchor='w')
|
||||
|
||||
label_6 = tkinter.Label(root, text='宜しくお願いします', font=('Arial',10,'bold'), bg='gray', fg='green')
|
||||
label_6.pack(padx=10, pady=(0, 10), fill='w', expand=True)
|
||||
|
||||
#フォントの確認
|
||||
print(font.families())
|
||||
|
||||
# ウィンドウのループ処理
|
||||
root.mainloop()
|
18
jktjoeaj703/task1/_ref/py_original_GUI-main/Basic/window.py
Normal file
18
jktjoeaj703/task1/_ref/py_original_GUI-main/Basic/window.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import tkinter
|
||||
|
||||
# ウィンドウの作成
|
||||
root = tkinter.Tk()
|
||||
root.title('Window practice')
|
||||
root.iconbitmap('icon.ico')
|
||||
root.geometry('300×800')
|
||||
root.resizable(0, 0) #サイズの変更禁止
|
||||
root.config(bg='red') #背景色
|
||||
|
||||
# サブウィンドウの作成
|
||||
sub_window = tkinter.Toplevel()
|
||||
sub_window.title('Second Window')
|
||||
sub_window.config(bg='#123123')
|
||||
sub_window.geometry('200×300+500+500')
|
||||
|
||||
# ウィンドウのループ処理
|
||||
root.mainloop()
|
@@ -0,0 +1,132 @@
|
||||
import tkinter
|
||||
import random
|
||||
import time
|
||||
|
||||
masu=[
|
||||
[0,0,0],
|
||||
[0,0,0],
|
||||
[0,0,0]
|
||||
]
|
||||
shirushi=0
|
||||
kachi=0
|
||||
FNT=("Times New Roman",60)
|
||||
def masume():
|
||||
# cvs.create_line(200,0,200,600,fill="gray", width=8) # 左の縦線
|
||||
# cvs.create_line(400,0,400,600,fill="gray", width=8) # 右の縦線
|
||||
# cvs.create_line(0,200,600,200,fill="gray", width=8) # 上の横線
|
||||
# cvs.create_line(0,400,600,400,fill="gray", width=8) # 下の横線
|
||||
|
||||
cvs.delete("all")
|
||||
# for文でマスを作成する
|
||||
for i in range(1,3):
|
||||
cvs.create_line(200*i,0,200*i,600,fill="gray",width=8)
|
||||
cvs.create_line(0,i*200,600,i*200,fill="gray",width=8)
|
||||
for y in range(3):
|
||||
for x in range(3):
|
||||
X=x*200
|
||||
Y=y*200
|
||||
if masu[y][x]==1:
|
||||
cvs.create_oval(X+20,Y+20,X+180,Y+180,outline="blue",
|
||||
width=12)
|
||||
if masu[y][x]==2:
|
||||
cvs.create_line(X+20,Y+20,X+180,Y+180,fill="red",width=12)
|
||||
cvs.create_line(X+180,Y+20,X+20,Y+180,fill="red",width=12)
|
||||
if shirushi==0:
|
||||
cvs.create_text(300,300,text="スタート",fill="navy",font=FNT)
|
||||
cvs.update()
|
||||
|
||||
def click(e):
|
||||
global shirushi
|
||||
if shirushi==9:
|
||||
replay()
|
||||
return
|
||||
if shirushi==1 or shirushi==3 or shirushi==5 or shirushi==7:
|
||||
return
|
||||
|
||||
mx=int(e.x/200)
|
||||
my=int(e.y/200)
|
||||
if mx>2:mx=2
|
||||
if my>2:my=2
|
||||
if masu[my][mx]==0:
|
||||
masu[my][mx]=1
|
||||
shirushi=shirushi+1
|
||||
masume()
|
||||
time.sleep(0.5)
|
||||
hantei()
|
||||
syouhai()
|
||||
if shirushi<9:
|
||||
computer()
|
||||
masume()
|
||||
time.sleep(0.5)
|
||||
hantei()
|
||||
syouhai()
|
||||
|
||||
def computer():
|
||||
global shirushi
|
||||
# 3つ揃うマスがあるか
|
||||
for y in range(3):
|
||||
for x in range(3):
|
||||
if masu[y][x]==0:
|
||||
masu[y][x]=2
|
||||
hantei()
|
||||
if kachi==2:
|
||||
shirushi=shirushi+1
|
||||
return
|
||||
masu[y][x]=0
|
||||
|
||||
def hantei():
|
||||
global kachi
|
||||
kachi = 0
|
||||
for n in range(1,3):
|
||||
# 縦に並んだかを判定する
|
||||
if masu[0][0]==n and masu[1][0]==n and masu[2][0]==n:
|
||||
kachi = n
|
||||
if masu[0][1]==n and masu[1][1]==n and masu[2][1]==n:
|
||||
kachi = n
|
||||
if masu[0][2]==n and masu[1][2]==n and masu[2][2]==n:
|
||||
kachi = n
|
||||
# 横に並んだかを判定する
|
||||
if masu[0][0]==n and masu[0][1]==n and masu[0][2]==n:
|
||||
kachi = n
|
||||
if masu[1][0]==n and masu[1][1]==n and masu[1][2]==n:
|
||||
kachi = n
|
||||
if masu[2][0]==n and masu[2][1]==n and masu[2][2]==n:
|
||||
kachi = n
|
||||
# 斜めに並んだかを判定する
|
||||
if masu[0][0]==n and masu[1][1]==n and masu[2][2]==n:
|
||||
kachi = n
|
||||
if masu[0][2]==n and masu[1][1]==n and masu[2][0]==n:
|
||||
kachi = n
|
||||
if kachi == 1:
|
||||
root.title(" ○ が3つ揃いました")
|
||||
if kachi == 2:
|
||||
root.title(" ✖️ が3つ揃いました")
|
||||
|
||||
def syouhai():
|
||||
global shirushi
|
||||
if kachi==1:
|
||||
cvs.create_text(300,300,text="あなたの勝ち",font=FNT,fill="cyan")
|
||||
shirushi=9
|
||||
if kachi==2:
|
||||
cvs.create_text(300,300,text="CPの勝ち",font=FNT,fill="gold")
|
||||
shirushi=9
|
||||
if kachi==0 and shirushi==9:
|
||||
cvs.create_text(300,300,text="引き分け",font=FNT,fill="lime")
|
||||
|
||||
def replay():
|
||||
global shirushi
|
||||
shirushi=0
|
||||
for y in range(3):
|
||||
for x in range(3):
|
||||
masu[y][x]=0
|
||||
masume()
|
||||
|
||||
|
||||
root=tkinter.Tk()
|
||||
root.title("三目並べ")
|
||||
root.resizable(False, False) #サイズの変更禁止
|
||||
root.bind("<Button>",click)
|
||||
cvs=tkinter.Canvas(width=600,height=600,bg="white")
|
||||
cvs.pack()
|
||||
masume()
|
||||
root.mainloop()
|
Reference in New Issue
Block a user