import tkinter as tk
#メインウィンドウを作成
baseGround =tk.Tk()
#ウィンドウのタイトルを設定
baseGround.title('Python-tkinter : VFXマクロ')
#画面のサイズ(横x縦)
baseGround.geometry('800x600')
#配置場所
"""
[place]
buttonA =tk.Button(
baseGround,text ='マクロA').place(x=50,y=100)
buttonB =tk.Button(
baseGround,text ='マクロB').place(x=100,y=150)
buttonC =tk.Button(
baseGround,text ='マクロC').place(x=150,y=200)
"""
buttonC =tk.Button(
baseGround,text ='マクロC', foreground = 'red').pack(anchor =tk.E)
"""
[pack]
buttonA =tk.Button(
baseGround,text ='マクロA').pack()
buttonB =tk.Button(
baseGround,text ='マクロB').pack(side =tk.LEFT)
buttonC =tk.Button(
baseGround,text ='マクロC').pack(side=tk.RIGHT)
"""
buttonC =tk.Button(
baseGround,text ='マクロC').pack(side=tk.RIGHT)
"""
[grid]
buttonD =tk.Button(
baseGround,text ='マクロD').grid(row=0,column =1)
buttonE =tk.Button(
baseGround,text ='マクロE').grid(row=0,column =2)
"""
#ラベル
label1= tk.Label(text='VFX便利ツール', foreground="black",background="white")
label1.pack()
#テキストボックス
label= tk.Label(text ='テキストボックス')
label.place(x=30,y=50)
txtBox =tk.Entry(width =20)
txtBox.place(x=30,y=70)
#複数行テキストボックス
textbox =tk.Text(width=10,height=15)
textbox.pack(anchor =tk.E)
#ラジオボタン
iiiitem= ['A', 'B', 'C', 'D']
val = tk.IntVar()
for i in range(len(iiiitem)):
tk.Radiobutton(baseGround,
value = i,
variable = val ,
text =iiiitem[i]
).pack(anchor = tk.W)
def choice():
ch =val.get()
print(iiiitem[ch]+"を選択しました。")
button = tk.Button(baseGround,
text="OK",
command =choice
).pack(side =tk.LEFT)
#チェックボタン
item =["お茶茶ちゃん","弁弁当当","傘傘傘","かば","鉄"]
check={}
# itemリストの要素の数だけ処理を繰り返す
for p in range(len(item)):
check[p] =tk.BooleanVar()
tk.Checkbutton(baseGround,
variable =check [p],
text= item[p]
).pack(anchor = tk.E)
# チェックボタンの状態を通知する関数
def select():
for p in check:
if check[p].get()==True:
print(item[p]+"をチェックしました。")
button =tk.Button(baseGround,text ="遠足",
command = select).pack(anchor =tk.E)
#スピンボックス
spinbox = tk.Spinbox(baseGround,value=("ボックス1","ボックス2","ボックス3"))
spinbox.pack()
#メニューバー
def callback():
print("プログラムを閉じる")
menubar =tk.Menu(baseGround)
baseGround.config(menu =menubar)
file = tk.Menu(menubar)
menubar.add_cascade(label="ファイル",menu =file)
file.add_command(label="New Project",command =callback)
file.add_command(label="New",command =callback)
edit = tk.Menu(menubar)
menubar.add_cascade(label="エディット",menu =edit)
edit.add_command(label="Undo",command =callback)
#テキストボックス、Entryは文字打てるようになります。
input_text =tk.Entry()
input_text.pack()
#値をラベルに表示
def btn_click():
TextInput =input_text.get() # 入力した値を取得
LabelOutput["text"] = TextInput # 入力した値をラベルに出力
#ボタン
btn = tk.Button(baseGround, text="入力値を出力",command=btn_click)
btn.pack()
#ラベル
label1 =tk.Label(text="入力値:")
label1.pack()
LabelOutput =tk.Label()
LabelOutput.pack()
#プログラムが終了しても画面が消えないようにするため
baseGround.mainloop()