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() 

 

#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() 

  

转载于:https://www.cnblogs.com/yunyaniu/p/8596243.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值