import tkinter as tk
root=tk.Tk() #建立視窗畫面
root.geometry("400x100") #決定視窗大小
lbl=tk.Label(text="LABLE") #製作標籤
btn=tk.Button(text="按一下") #製作按鈕
lbl.pack()
btn.pack()
tk.mainloop()
===========
import tkinter as tk
def showlabel():
lbl.configure(text="不要亂按") #標籤重置
root=tk.Tk()
root.geometry("400x100")
lbl=tk.Label(text="LABLE")
btn=tk.Button(text="按一下",command=showlabel) #修改 按一下 執行的函數
lbl.pack()
btn.pack()
tk.mainloop()
============
import tkinter as tk
import random
def fate01():
fates=["大吉","中吉","小吉"]
fatesD=random.choice(fates)
lbl.configure(text=fatesD)
root=tk.Tk()
root.geometry("400x100")
lbl=tk.Label(text="信則霊")
btn=tk.Button(text="按一下求籤",command=fate01)
lbl.pack()
btn.pack()
tk.mainloop()
沒有留言:
張貼留言