天天看點

Python之tkinter:調用python庫的tkinter帶你進入GUI世界(一)——Jason niu

#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() 
           
Python之tkinter:調用python庫的tkinter帶你進入GUI世界(一)——Jason niu
#tkinter應用案例一:
import tkinter as tk 
app=tk.Tk() 
app.title("Jason niu工作室") 
theLabel=tk.Label(app,text="進入GUI世界,請開始你的表演!") 
theLabel.pack() 
app.mainloop() 
           
Python之tkinter:調用python庫的tkinter帶你進入GUI世界(一)——Jason niu
#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() 
           
Python之tkinter:調用python庫的tkinter帶你進入GUI世界(一)——Jason niu
#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() 
           
Python之tkinter:調用python庫的tkinter帶你進入GUI世界(一)——Jason niu
#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() 
           

  

Python之tkinter:調用python庫的tkinter帶你進入GUI世界(一)——Jason niu

轉載于:https://www.cnblogs.com/yunyaniu/p/8596243.html