码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • python - 第15章 GUI的最终选择 Tkinter


    文章目录

    • tk1
    • tk2
    • tk3 添加图片
    • tk4 图片作背景

    tk1

    import tkinter as tk
    
    app=tk.Tk()
    app.title("这是标题")   # 显示标题
    
    theLabel=tk.Label(app,text='窗口程序!') # 显示文本,图片,图标
    theLabel.pack() # 自动调节组件尺寸
    
    app.mainloop()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    在这里插入图片描述

    tk2

    import tkinter as tk
    
    class APP:
        def __init__(self,master):
            frame=tk.Frame(master)
            frame.pack(side=tk.LEFT,padx=10,pady=10)
    
            self.hi_there=tk.Button(frame,text='打招呼',fg='white',bg='black',command=self.say_hi)
            self.hi_there.pack()
    
        def say_hi(self):
            print('大家好!')
    
    root=tk.Tk()
    app=APP(root)
    
    root.mainloop()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    在这里插入图片描述

    tk3 添加图片

    from tkinter import *
    
    root=Tk()
    textLabel = Label(root,text='文字配图片',padx=10)
    
    textLabel.pack(side=LEFT)
    
    photo = PhotoImage(file='photo1.png')
    imgLabel = Label(root, image=photo)
    imgLabel.pack(side=RIGHT)
    mainloop()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    在这里插入图片描述

    tk4 图片作背景

    from tkinter import *
    
    root=Tk()
    photo = PhotoImage(file='photo1.png')
    theLabel = Label(root,text='我是一只大熊猫!\n哈哈哈哈哈!',justify=LEFT,image=photo,compound=CENTER,
                     font=('微软雅黑',20),
                     fg='green')
    theLabel.pack()
    mainloop()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    在这里插入图片描述

  • 相关阅读:
    自己实现 SpringMVC 底层机制 系列之-实现任务阶段 5- 完成 Spring 容器对象的自动装配 -@Autowried
    内存还有几十G,为何jvm会oom crash
    Java打印输入数字的个位,十位,百位,千位,万位的数字
    软件设计模式白话文系列(五)建造者模式
    10.1K star !牛逼了!开源技术速查表,推荐人手一份!
    国民技术 N32G45x RTThread 定时器 串口接收不定长数据
    es 存储文档得大小_Elasticsearch的用例:文档存储
    智能文档控制——文档的智能归档、捕获、索引、访问和协作
    C语言第十课(上):编写井字棋游戏(综合练习1)
    Springboot+vue的导师双选管理系统(有报告)。Javaee项目,springboot vue前后端分离项目。
  • 原文地址:https://blog.csdn.net/qq_45823731/article/details/133777507
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号