1.按钮

tkBtton.py

 import tkinter

 root = tkinter.Tk()
 btn1 = tkinter.Button(root, anchor=tkinter.E,\
     text='Button1', width=40, height=5)
 btn1.pack()
 btn2 = tkinter.Button(root, \
     text='Button2', bg='blue')
 btn2.pack()
 btn3 = tkinter.Button(root, \
     text='Button3', width=14, height=1)
 btn3.pack()
 btn4 = tkinter.Button(root, \
     text='Button4', width=60, height=5, state=tkinter.DISABLED)
 btn4.pack()
 root.mainloop()

2.标签

tkLabel.py

 import tkinter

 root = tkinter.Tk()

 lbl1 = tkinter.Label(root, anchor=tkinter.E,
     bg='blue', fg='red', text='Python', width=30, height=5)
 lbl1.pack()

 lbl2 = tkinter.Label(root, text='Python GUI\nTkinter',
     justify=tkinter.LEFT, width=30, height=5)
 lbl2.pack()

 lbl3 = tkinter.Label(root, text='Python GUI\nTkinter',
     justify=tkinter.RIGHT, width=30, height=5)
 lbl3.pack()

 lbl4 = tkinter.Label(root, text='Python GUI\nTkinter',
     justify=tkinter.CENTER, width=30, height=5)
 lbl4.pack()

 root.mainloop()

3.单选框、复选框

tkCheck.py

 import tkinter

 root = tkinter.Tk()

 r = tkinter.StringVar()
 r.set(')
 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio1')
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio2')
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio3')
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio4')
 radio.pack()

 c = tkinter.IntVar()
 c.set(1)
 check = tkinter.Checkbutton(root, text='CheckButton', variable=c, onvalue=1, offvalue=2)
 check.pack()

 root.mainloop()
 print(r.get())
 print(c.get())

4.单选框、复选框的平坦样式

tkRCButton.py

 import tkinter

 root = tkinter.Tk()

 r = tkinter.StringVar()
 r.set(')
 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio1', indicatoron=0)
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio2', indicatoron=0)
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio3', indicatoron=0)
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio4', indicatoron=0)
 radio.pack()

 c = tkinter.IntVar()
 c.set(1)
 check = tkinter.Checkbutton(root, text='CheckButton', variable=c, onvalue=1, offvalue=2, indicatoron=0)
 check.pack()

 root.mainloop()
 print(r.get())
 print(c.get())

5.文本框

tkEntry.py

 import tkinter

 root = tkinter.Tk()

 entry1 = tkinter.Entry(root, show='*' )
 entry1.pack()

 entry2 = tkinter.Entry(root, show=')
 entry2.pack()

 entry3 = tkinter.Entry(root, bg='red', fg='blue')
 entry3.pack()

 entry4 = tkinter.Entry(root, selectbackground='red',\
                             selectforeground='gray')
 entry4.pack()

 entry5 = tkinter.Entry(root, state=tkinter.DISABLED)
 entry5.pack()

 edit1 = tkinter.Text(root, selectbackground='red',
                             selectforeground='gray')
 edit1.pack()

 root.mainloop()

Python -- Gui编程 -- Tkinter的使用 -- 基本控件的更多相关文章

  1. Python:GUI之tkinter学习笔记1控件的介绍及使用

    相关内容: tkinter的使用 1.模块的导入 2.使用 3.控件介绍 Tk Button Label Frame Toplevel Menu Menubutton Canvas Entry Mes ...

  2. Python GUI编程(Tkinter) windows界面开发

    Python实现GUI简单的来说可以调用Tkinter库,这样一般的需求都可以实现,显示简单的windows窗口代码如下: python_gui.py 1 #!C:\Python27\python.e ...

  3. Python GUI编程(Tkinter)(一)

    tk官网的教程学习: https://tkdocs.com/tutorial/firstexample.html 学习blog: https://www.cnblogs.com/aland-1415/ ...

  4. Python GUI编程(Tkinter)Ⅱ

    Tkinter 组件 Tkinter的提供各种控件,如按钮,标签和文本框,一个GUI应用程序中使用.这些控件通常被称为控件或者部件. 目前有15种Tkinter的部件.我们提出这些部件以及一个简短的介 ...

  5. python GUI编程tkinter示例之目录树遍历工具

    摘录 python核心编程 本节我们将展示一个中级的tkinter应用实例,这个应用是一个目录树遍历工具:它会从当前目录开始,提供一个文件列表,双击列表中任意的其他目录,就会使得工具切换到新目录中,用 ...

  6. Python GUI编程--Tkinter

    今天看到了GUI编程,书上推荐用wxPython,去官网上看了看,发现Windows的最高支持到2.7,我用的是3.4版本,咋办,用自带的库--Tkinter呗,它是Python的默认GUI库,几乎是 ...

  7. Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框

    1.消息框 tkMessageBox.py import tkinter from tkinter import messagebox def cmd(): global n global butto ...

  8. Python -- Gui编程 -- Tkinter的使用 -- 菜单与画布

    1.菜单 tkMenu.py import tkinter root = tkinter.Tk() menu = tkinter.Menu(root) submenu = tkinter.Menu(m ...

  9. python大法好——ython GUI编程(Tkinter)

    Python GUI编程(Tkinter) Python 提供了多个图形开发界面的库,几个常用 Python GUI 库如下: Tkinter: Tkinter 模块(Tk 接口)是 Python 的 ...

随机推荐

  1. Android属性动画之ValueAnimator的介绍

    之前两篇博客,介绍的是ObjectAnimator作用与某一个控件的某一个属性.但我们的ValueAnimator它本身并不会作用与任何一个属性,它本身也不会提供任何一种动画.它简单的来说,就是一个数 ...

  2. HDU6205 Coprime Sequence 2017-05-07 18:56 36人阅读 评论(0) 收藏

    Coprime Sequence                                                        Time Limit: 2000/1000 MS (Ja ...

  3. hdu 5003 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5003 记得排序后输出 #include <cstdio> #include <cstring& ...

  4. 网页程序 vs 桌面程序

    网页程序 vs 桌面程序 阅读:  评论:  作者:Rybby  日期:  来源:rybby.com 所谓的网页程序就是指以网页作为程序的操作界面,通过脚本语言“javascript”或其它客户端语言 ...

  5. java web 入门实例servlet篇(显示后台数据库列表,删除某一条记录并显示)

    编写过程中需要注意的问题: 1.建立eclipse动态web工程时,需要改写编译后class文件的位置,通常情况下是这个位置:/WebContent/WEB-INF/classes 2.配置的页面链接 ...

  6. 日期类的加减及java中所以日期类的操作算法大全

    1.计算某一月份的最大天数 1Calendar time=Calendar.getInstance();2time.clear();3time.set(Calendar.YEAR,year); //y ...

  7. Beta版本使用说明

    一.产品介绍 我们做的是一个基于安卓的手机app,通过连接图书馆的数据库,实现查询图书馆的书目信息的功能. 二.软件运行 我们只做了安卓版本,需要在安卓环境下运行. 三.软件结构 本软件主要包括客户端 ...

  8. EBS xml publisher中文乱码

    http://www.cnblogs.com/benio/archive/2011/11/22/2259313.html   由于本机环境问题,导致做的xml publisher报表跑不出来. 无法显 ...

  9. Transaction And Lock--使用资源锁来控制并发

    写过程序的朋友都知道,在多线程处理时,对于非线程安全的对象,需用使用锁定特定对象(LOCK)的方法来保证串行操作.曾经有位开发询问我,在SQL Server内部是否有类似的实现方法来控制某一操作不能并 ...

  10. .NET 任务调度Quartz系列(1)——自建定时任务

    在我们平时项目中经常会遇到定时任务,比如定时同步数据,定时备份数据,定时统计数据等,定时任务我们都知道使用Quartz.net,此系列写的也是Quartz,但是在此之前,我们先用其他方式做个简单的定时 ...