python-GUI之tkinter的学习
最近看了哔哩哔哩的python的学习,直接看代码吧,以后会更新
先来个基础的
import tkinter as tk #导入包 app = tk.Tk() #抽象出一个GUI
app.title("first GUI") #设置这个窗口的标题
thelable = tk.Label(app, text = "这是一个窗口") #标签,要先把参数app给传进去,比较常用
thelable.pack() #这是对这个标签进行排版,可以在里面设置参数自己设置 app.mainloop()#必须要加
加了个按钮,点击按钮就可以出现hello
import tkinter as tk class App:
def __init__(self, master):#构造函数,对App进行初始化
frame = tk.Frame(master)#按钮框架
frame.pack(side = tk.LEFT,padx = 100,pady = 100)#设置参数自定义 self.hi_here = tk.Button(frame, text = 'hello',fg='blue',bg='black',command = self.hello)#bg,fg背景前景色,command为按下按钮发生的事件
self.hi_here.pack()
def hello(self):
print("hello") root = tk.Tk()
App(root) root.mainloop()
这次添加一个图片,文字在坐,图片在右边
from tkinter import *
import tkinter as tk
root = tk.Tk() textlabel = tk.Label(root, text = "非18\n不可观看",#可以转义字符
justify = LEFT,#设置左对齐
padx = 10)
textlabel.pack(side = tk.LEFT) photo = PhotoImage(file = '18.gif')#得到图片,要是gif类型的
imglabel = tk.Label(root,image = photo)#添加图片
imglabel.pack(side = tk.RIGHT)
root.mainloop()
图片和文字在一起
from tkinter import *
import tkinter as tk
root = tk.Tk()
photo = PhotoImage(file = '18.gif')#得到图片,要是gif类型的
textlabel = tk.Label(root, text = "非18\n不可观看",#可以转义字符
justify = LEFT,#设置左对齐
padx = 10,
image = photo,
compound = CENTER)#设置为图片和文字混合,图片在中间
textlabel.pack(side = tk.LEFT)
root.mainloop()
图片和文字加按钮,按下按钮文字变换
from tkinter import * def change():
var.set("小孩子不许骗人") root = Tk()
frame1 = Frame(root)#如果是from tkinter import *,则调用Frame的时候就不用tk.Frame()
frame2 = Frame(root) var = StringVar()
var.set("18才能看,你18了么")
textlabel = Label(frame1,
textvariable = var,#将文字设置成可变的,类型应该为StringVar
justify = LEFT)
textlabel.pack(side = LEFT) photo = PhotoImage(file = '18.gif')
imglabel = Label(frame1, image = photo)
imglabel.pack(side = RIGHT) button = Button(frame2,text ='我已18',command = change)
button.pack() frame1.pack(padx = 10, pady = 10)
frame2.pack(padx = 10, pady = 10) mainloop()
python-GUI之tkinter的学习的更多相关文章
- Python GUI之tkinter窗口视窗教程大集合(看这篇就够了) JAVA日志的前世今生 .NET MVC采用SignalR更新在线用户数 C#多线程编程系列(五)- 使用任务并行库 C#多线程编程系列(三)- 线程同步 C#多线程编程系列(二)- 线程基础 C#多线程编程系列(一)- 简介
Python GUI之tkinter窗口视窗教程大集合(看这篇就够了) 一.前言 由于本篇文章较长,所以下面给出内容目录方便跳转阅读,当然也可以用博客页面最右侧的文章目录导航栏进行跳转查阅. 一.前言 ...
- Python GUI with Tkinter (from youtube) 在youtube上能找到很多编程视频...
Python GUI with Tkinter - 1 - Introduction以上链接是一个python tkinter视频系列的第一讲的链接.虽然英语不好,但是,程序还是看得懂的(照着做就可以 ...
- Python GUI编程(Tkinter) windows界面开发
Python实现GUI简单的来说可以调用Tkinter库,这样一般的需求都可以实现,显示简单的windows窗口代码如下: python_gui.py 1 #!C:\Python27\python.e ...
- Python:GUI之tkinter学习笔记1控件的介绍及使用
相关内容: tkinter的使用 1.模块的导入 2.使用 3.控件介绍 Tk Button Label Frame Toplevel Menu Menubutton Canvas Entry Mes ...
- Python GUI工具Tkinter以及拖拉工具Page安装
如果使用Tkinter作为Python GUI工具,我们需要安装Tkinter,这个使用conda或者pip即可: conda install -c anaconda tk 为了提高界面编写效率,可以 ...
- Python -- Gui编程 -- Tkinter的使用 -- 基本控件
1.按钮 tkBtton.py import tkinter root = tkinter.Tk() btn1 = tkinter.Button(root, anchor=tkinter.E,\ te ...
- Python:GUI之tkinter学习笔记之messagebox、filedialog
相关内容: messagebox 介绍 使用 filedialog 介绍 使用 首发时间:2018-03-04 22:18 messagebox: 介绍:messagebox是tkinter中的消息框 ...
- Python:GUI之tkinter学习笔记3事件绑定
相关内容: command bind protocol 首发时间:2018-03-04 19:26 command: command是控件中的一个参数,如果使得command=函数,那么点击控件的时候 ...
- Python:GUI之tkinter学习笔记2界面布局显示
相关内容: pack 介绍 常用参数 使用情况 常用函数 grid 介绍 常用参数 使用情况 常用函数 place 介绍 常用参数 使用情况 常用函数 首发时间:2018-03-04 14:20 pa ...
- Python GUI编程--Tkinter
今天看到了GUI编程,书上推荐用wxPython,去官网上看了看,发现Windows的最高支持到2.7,我用的是3.4版本,咋办,用自带的库--Tkinter呗,它是Python的默认GUI库,几乎是 ...
随机推荐
- WebForm下的$.ajax中contentType: “application/json” 的用法
不使用contentType: “application/json”则data可以是对象 $.ajax({ url: actionurl, type: "POST", datTyp ...
- C# 通过word模板动态生成Word
object oMissing = System.Reflection.Missing.Value; Word._Application oWord = new Word.Application(); ...
- tp5简要
1.实例化模型 namespace app\web\controller; use think\Controller; use app\web\model\Member; use think\Load ...
- 个性化 UIAlertController
系统的 UIAlertController 封装的很漂亮,用block代替之前 UIAlertView 的代理,用起来更方便的,但是其曝露出来的接口也不多如果要个性化一些东西,比如字体大小.颜色就不是 ...
- C语言入门教程-(5)格式化输入输出
1.输入和输出 在程序的使用中,我们经常可以看的这么一个场景:用户需要输入数据,经过程序运算,得到结果后输出.在C语言中,输入数据和输出数据都是由库函数完成的,通过语句来输入/输出. 2.格式化输出— ...
- Verilog_Day2
Verilog_Day1 在CSDN博客上.http://blog.csdn.net/m0_38073085 第三章: 书上基本知识 每个Verilog程序包括4个主要部分:端口定义,I/O说明,内部 ...
- Oracle单节点_Grid_Infrastructure_DB_安装过程图解(一/三)
首先进行各种准备: ASMLIB的准备,用户和目录的创建. 安装好Linux之后(采用了OEL 5.7),查看是否光盘中包含ASMLIB:
- python基础学习1-内置函数
#!/usr/bin/env python # -*- coding:utf-8 -*- 系统内置函数 n =abs(-1) #绝对值 print(n) #bytes()函数 s="离开&q ...
- 【转载】COM 组件设计与应用(二)——GUID 和 接口
原文:http://vckbase.com/index.php/wv/1203.html COM 组件设计与应用 系列文章:http://vckbase.com/index.php/piwz?& ...
- Ceph学习之路(三)Ceph luminous版本部署
1.配置ceph.repo并安装批量管理工具ceph-deploy [root@ceph-node1 ~]# vim /etc/yum.repos.d/ceph.repo [ceph] name=Ce ...