#tkinter應用案例五:Label組件設圖片為背景並點擊按鈕觸發事件
from tkinter import *
from PIL.ImageTk import PhotoImage
from sqlalchemy.testing.exclusions import compound
def callback():
var.set("正在進入學習空間……")
root=Tk() #實例化TK
root.title("Jason niu工作室")
frame1=Frame(root)
frame2=Frame(root)
var=StringVar()
var.set("歡迎進入Jason niu工作室\n主要模塊有:\n機器學習\n深度學習\n強化學習\n遷移學習\n區塊鏈技術")
photo=PhotoImage(file="G:\創業\背景圖01.jpg")
imageLabel=Label(frame1)
imageLabel.pack(side=RIGHT)
textLabel=Label(root,
textvariable=var,
justify=CENTER,
image=photo,
compound=CENTER,
font=("楷體",20,),fg="yellow")
textLabel.pack()
theButton=Button(frame1,text="我想學習區塊鏈技術的應用",font=("黑體",),fg="red",command=callback)
theButton.pack()
frame1.pack(padx=10,pady=10)
frame2.pack(padx=10,pady=10)
mainloop()

#tkinter應用案例一:
import tkinter as tk
app=tk.Tk()
app.title("Jason niu工作室")
theLabel=tk.Label(app,text="進入GUI世界,請開始你的表演!")
theLabel.pack()
app.mainloop()

#tkinter應用案例二:
import tkinter as tk
from tkinter import *
from PIL.ImageTk import PhotoImage
root=tk.Tk()
textLabel=Label(root,
text="歡迎進入Jason niu工作室\n主要模塊有:\n機器學習\n深度學習\n強化學習\n遷移學習\n區塊鏈技術",
justify=CENTER,
padx=0)
textLabel.pack()
photo=PhotoImage(file="G:\創業\雲崖牛logo小.png")
imageLabel=Label(root,image=photo)
imageLabel.pack()
mainloop()

#tkinter應用案例三:將GUI封裝成類
import tkinter as tk
class APP:
def __init__(self,master):
frame=tk.Frame(master)
frame.pack(side=tk.LEFT,padx=50,pady=50)
self.hi_there=tk.Button(frame,text="歡迎進入Jason niu工作室",fg="yellow",bg="black",command=self.say_hi)
self.hi_there.pack()
def say_hi(self):
print("你好,歡迎訪問“一個處女座程序猿的博客”!")
root=tk.Tk()
app=APP(root)
root.mainloop()

#tkinter應用案例四:Label組件將圖片設為背景
import tkinter as tk
from tkinter import *
from PIL.ImageTk import PhotoImage
from sqlalchemy.testing.exclusions import compound
root=tk.Tk()
root.title("Jason niu工作室")
photo=PhotoImage(file="G:\創業\背景圖01.jpg")
textLabel=Label(root,
text="歡迎進入Jason niu工作室\n主要模塊有:\n機器學習\n深度學習\n強化學習\n遷移學習\n區塊鏈技術",
justify=CENTER,
image=photo,
compound=CENTER,
font=("楷體",20,),
fg="yellow")
textLabel.pack()
mainloop()
