日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button的command/Label/PhotoImage/封装为类)

發(fā)布時間:2025/3/21 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button的command/Label/PhotoImage/封装为类) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Python之tkinter:動態(tài)演示調(diào)用python庫的tkinter帶你進入GUI世界(Button的command/Label/PhotoImage/封裝為類)

?

?

?

目錄

tkinter應用案例五

1、Label組件設圖片為背景并點擊按鈕觸發(fā)事件

2、窗口內(nèi)添加標題

3、窗口內(nèi)添加多個小標題

4、將GUI封裝為類

5、Label組件將圖片設為背景


?

?

tkinter應用案例五

1、Label組件設圖片為背景并點擊按鈕觸發(fā)事件

#tkinter應用案例五:Label組件設圖片為背景并點擊按鈕觸發(fā)事件 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區(qū)塊鏈技術")photo=PhotoImage(file="G:\創(chuàng)業(yè)\背景圖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="我想學習區(qū)塊鏈技術的應用",font=("黑體",),fg="red",command=callback) theButton.pack() frame1.pack(padx=10,pady=10) frame2.pack(padx=10,pady=10)mainloop()

?

2、窗口內(nèi)添加標題

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

?

3、窗口內(nèi)添加多個小標題

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

?

?

4、將GUI封裝為類

#tkinter應用案例三:將GUI封裝成類 import tkinter as tkclass 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()

?

?

5、Label組件將圖片設為背景

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

  

?

?

?

總結

以上是生活随笔為你收集整理的Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button的command/Label/PhotoImage/封装为类)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。