tkinter

Python

install & import

標準ライブラリなのでインストールは不要

import tkinter

make window

window = tkinter.Tk()

# ウィンドウのタイトル
window.title('title')
# ウィンドウのサイズと左上座標の位置
window.geometry('500x400+500+300')
# ウィンドウの透明度
window.attributes('-alpha', 0.7)

label

label1 = tkinter.Label(text=u'ラベル名')
label1.place(x=x座標, y=y座標)

entry

entry1 = tkinter.Entry(width=50)
entry1.insert(tkinter.END, 'プレイスホルダー')
entry1.pack()

button

event がないと(https://qiita.com/mizuno_jin/items/7c1f5a90dfb89bd64bff)のエラーが起きる

def deleteLabelValue(event):
  print(event)
  entry1.delete(0, tkinter.END)

button1 = tkinter.Button(text=u'削除', width=50)
button1.bind("<Button-1>", deleteLavelValue)
button1.pack()

checkbutton

# はじめからチェックがついているようにする
Var1 = tkinter.BooleanVar()
Var1.set(True)

checkbutton1 = tkinter.Checkbutton(text=u'項目1', variable=Var1)

tkinter内にコンソールWidgetsを作る方法

https://zenn.dev/blackhat_d/articles/20230220-tkinter-console-9a91eff4400154

BACK