目錄
tkinter應用案例五
1、Label元件設圖檔為背景并點選按鈕觸發事件
2、視窗内添加标題
3、視窗内添加多個小标題
4、将GUI封裝為類
5、Label元件将圖檔設為背景
#tkinter應用案例五:Label元件設圖檔為背景并點選按鈕觸發事件
from tkinter import *
def callback():
var.set("正在進入學習空間……")
root=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應用案例一:
app=tk.Tk()
app.title("Jason niu工作室")
theLabel=tk.Label(app,text="進入GUI世界,請開始你的表演!")
theLabel.pack()
app.mainloop()

#tkinter應用案例二:
import tkinter as tk
root=tk.Tk()
text="歡迎進入Jason niu工作室\n主要子產品有:\n機器學習\n深度學習\n強化學習\n遷移學習\n區塊鍊技術",
justify=CENTER,
padx=0)
photo=PhotoImage(file="G:\創業\雲崖牛logo小.png")
imageLabel=Label(root,image=photo)
imageLabel.pack()
mainloop()
#tkinter應用案例三:将GUI封裝成類
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元件将圖檔設為背景
text="歡迎進入Jason niu工作室\n主要子產品有:\n機器學習\n深度學習\n強化學習\n遷移學習\n區塊鍊技術",
font=("楷體",20,),
fg="yellow")