Python之tkinter:调用python库的tkinter带你进入GUI世界(一)——Jason niu
2024-09-01 01:15:14
#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()
最新文章
- 精确率与召回率,RoC曲线与PR曲线
- 问题解决——CVSListBox的使用
- Linux 常用命令笔记 (持续更新)
- Leetcode Maximum Depth of Binary Tree
- Codeforces Round #332 (Div. 2) B. Spongebob and Joke 水题
- 前端自动生成/加载CSS
- app启动其他应用
- Java设置的读书笔记和集合框架Collection API
- hud 2099
- 反射应用--IOC和AOP
- cmd 与 bash 基础命令入门
- Spring+SpringMVC+MyBatis+easyUI整合进阶篇(十五)阶段总结
- TypeScript-封装
- [C++]PAT乙级1002.写出这个数(20/20)
- linux脚本实现scp命令自动输入密码和yes/no等确认信息
- c++下基于windows socket的多线程服务器(基于TCP协议)
- delphi 域名转ip并判断ip是否可以联通
- 用开源项目ExpandableTextView打造可以下拉扩展的TextView
- Spring AOP的注解方式实现
- Tomcat安全配置与性能优化