Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button的command/Label/PhotoImage/封装为类)
生活随笔
收集整理的這篇文章主要介紹了
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應(yīng)用案例五
1、Label組件設(shè)圖片為背景并點擊按鈕觸發(fā)事件
2、窗口內(nèi)添加標題
3、窗口內(nèi)添加多個小標題
4、將GUI封裝為類
5、Label組件將圖片設(shè)為背景
?
?
tkinter應(yīng)用案例五
1、Label組件設(shè)圖片為背景并點擊按鈕觸發(fā)事件
#tkinter應(yīng)用案例五:Label組件設(shè)圖片為背景并點擊按鈕觸發(fā)事件 from tkinter import *def callback():var.set("正在進入學(xué)習(xí)空間……")root=Tk() root.title("Jason niu工作室") frame1=Frame(root) frame2=Frame(root)var=StringVar() var.set("歡迎進入Jason niu工作室\n主要模塊有:\n機器學(xué)習(xí)\n深度學(xué)習(xí)\n強化學(xué)習(xí)\n遷移學(xué)習(xí)\n區(qū)塊鏈技術(shù)")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="我想學(xué)習(xí)區(qū)塊鏈技術(shù)的應(yīng)用",font=("黑體",),fg="red",command=callback) theButton.pack() frame1.pack(padx=10,pady=10) frame2.pack(padx=10,pady=10)mainloop()?
2、窗口內(nèi)添加標題
#tkinter應(yīng)用案例一: app=tk.Tk() app.title("Jason niu工作室") theLabel=tk.Label(app,text="進入GUI世界,請開始你的表演!") theLabel.pack() app.mainloop()?
3、窗口內(nèi)添加多個小標題
#tkinter應(yīng)用案例二: import tkinter as tkroot=tk.Tk() textLabel=Label(root, text="歡迎進入Jason niu工作室\n主要模塊有:\n機器學(xué)習(xí)\n深度學(xué)習(xí)\n強化學(xué)習(xí)\n遷移學(xué)習(xí)\n區(qū)塊鏈技術(shù)", 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應(yīng)用案例三:將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組件將圖片設(shè)為背景
#tkinter應(yīng)用案例四:Label組件將圖片設(shè)為背景 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機器學(xué)習(xí)\n深度學(xué)習(xí)\n強化學(xué)習(xí)\n遷移學(xué)習(xí)\n區(qū)塊鏈技術(shù)",justify=CENTER,image=photo,compound=CENTER,font=("楷體",20,),fg="yellow") textLabel.pack()mainloop()
?
?
?
總結(jié)
以上是生活随笔為你收集整理的Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button的command/Label/PhotoImage/封装为类)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Crawler之Scrapy:数据挖掘必
- 下一篇: Python之tkinter:动态演示调