目的
pythonで「A と、見せかけて B」と、出力してくるコードをtkinterで動かす際の備忘録です
準備
tkinterは、PythonでGUIを組むことのできるツールです。
以下を参考にさせて頂きます
コード
sample.py
import tkinter as tk
import random
l = ["りんご",
"みかん",
"いちご",
"パイナップル",
"ドラゴンフルーツ"]
def bot():
string1=random.choice(l)
string2=random.choice(l)
string=string1+" と、見せかけて "+string2
label = tk.Label(text=string) # ラベルを定義
x = random.randrange(640)
y = random.randrange(480)
label.place(x=x, y=y) # ラベルを設置
window = tk.Tk() #ウィンドウを定義
window.title("Title") #ウィンドウタイトルを設定
window.geometry("640x480") #ウィンドウサイズを設定
btn = tk.Button(window, text='と、見せかけて', command = bot) #ボタンの作成
btn.place(x=10, y=10)
window.mainloop() #メインループとして待機状態にする